stateless_test.cpp 985 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Boost.Function library
  2. // Copyright Douglas Gregor 2001-2003. Use, modification and
  3. // distribution is subject to the Boost Software License, Version
  4. // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. // For more information, see http://www.boost.org
  7. #include <boost/function.hpp>
  8. #include <boost/core/lightweight_test.hpp>
  9. #include <stdexcept>
  10. #include <new>
  11. struct stateless_integer_add {
  12. int operator()(int x, int y) const { return x+y; }
  13. void* operator new(std::size_t n)
  14. {
  15. BOOST_ERROR( "stateless_integer_add incorrectly allocated" );
  16. return ::operator new( n );
  17. }
  18. void* operator new(std::size_t, void* p)
  19. {
  20. return p;
  21. }
  22. void operator delete(void* p) throw()
  23. {
  24. BOOST_ERROR( "stateless_integer_add incorrectly deallocated" );
  25. return ::operator delete( p );
  26. }
  27. };
  28. int main()
  29. {
  30. boost::function2<int, int, int> f;
  31. f = stateless_integer_add();
  32. return boost::report_errors();
  33. }