nested.pass.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is dual licensed under the MIT and the University of Illinois Open
  6. // Source Licenses. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. // UNSUPPORTED: c++98, c++03
  10. // <functional>
  11. // template<CopyConstructible Fn, CopyConstructible... Types>
  12. // unspecified bind(Fn, Types...);
  13. // template<Returnable R, CopyConstructible Fn, CopyConstructible... Types>
  14. // unspecified bind(Fn, Types...);
  15. // http://llvm.org/bugs/show_bug.cgi?id=16343
  16. #include <cmath>
  17. #include <functional>
  18. #include <cassert>
  19. struct power
  20. {
  21. template <typename T>
  22. T
  23. operator()(T a, T b)
  24. {
  25. return std::pow(a, b);
  26. }
  27. };
  28. struct plus_one
  29. {
  30. template <typename T>
  31. T
  32. operator()(T a)
  33. {
  34. return a + 1;
  35. }
  36. };
  37. int
  38. main()
  39. {
  40. using std::placeholders::_1;
  41. auto g = std::bind(power(), 2, _1);
  42. assert(g(5) == 32);
  43. assert(std::bind(plus_one(), g)(5) == 33);
  44. }