function.cxx 818 Bytes
Newer Older
1 2 3 4 5 6 7 8 9
//=========================================================================
//  Copyright (c) Kitware, Inc.
//  All rights reserved.
//  See LICENSE.txt for details.
//
//  This software is distributed WITHOUT ANY WARRANTY; without even
//  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
//  PURPOSE.  See the above copyright notice for more information.
//=========================================================================
10 11
#include <functional>

12 13 14
struct favorite_int
{
  int operator()() { return 42; }
15 16
};

17 18 19
struct conditional_int
{
  int operator()(float x) { return 2 * static_cast<int>(x); }
20 21 22 23 24 25 26 27
};

int main(int, char**)
{
  std::function<int()> f;
  f = favorite_int();
  std::function<int()> g;
  g = std::bind<float>(conditional_int(), 21.0);
28
  return (f() == 42 && g() == 42) ? 0 : 1;
29
}