functor.cpp 982 B

12345678910111213141516171819202122232425262728293031323334
  1. // Copyright (C) 2009-2012 Lorenzo Caminiti
  2. // Distributed under the Boost Software License, Version 1.0
  3. // (see accompanying file LICENSE_1_0.txt or a copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. // Home at http://www.boost.org/libs/functional/overloaded_function
  6. #include "identity.hpp"
  7. #include <boost/functional/overloaded_function.hpp>
  8. #include <boost/core/lightweight_test.hpp>
  9. int main() {
  10. //[identity_calls
  11. BOOST_TEST(identity_s("abc") == "abc");
  12. BOOST_TEST(identity_i(123) == 123);
  13. BOOST_TEST(identity_d(1.23) == 1.23);
  14. //]
  15. //[identity_functor
  16. boost::overloaded_function<
  17. const std::string& (const std::string&)
  18. , int (int)
  19. , double (double)
  20. > identity(identity_s, identity_i, identity_d);
  21. // All calls via single `identity` function.
  22. BOOST_TEST(identity("abc") == "abc");
  23. BOOST_TEST(identity(123) == 123);
  24. BOOST_TEST(identity(1.23) == 1.23);
  25. //]
  26. return boost::report_errors();
  27. }