//////////////////////////////////////////////////////////////////////////// // lazy_make_pair_tests.cpp // // lazy make_pair test solving the optimizer problem. // //////////////////////////////////////////////////////////////////////////// /*============================================================================= Copyright (c) 2001-2007 Joel de Guzman Copyright (c) 2015 John Fletcher Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) ==============================================================================*/ #include #include #include #include namespace boost { namespace phoenix { #ifdef BOOST_RESULT_OF_USE_TR1 namespace result_of { template < typename Arg1 , typename Arg2 > class make_pair { public: typedef typename boost::remove_reference::type Arg1Type; typedef typename boost::remove_reference::type Arg2Type; typedef std::pair type; }; } #endif namespace impl { struct make_pair { #ifdef BOOST_RESULT_OF_USE_TR1 template struct result; // This fails with -O2 unless refs are removed from A1 and A2. template struct result { typedef typename result_of::make_pair::type type; }; #else template struct result; template struct result : boost::remove_reference > {}; #endif template #ifdef BOOST_RESULT_OF_USE_TR1 typename result::type #else std::pair #endif operator()(A0 const & a0, A1 const & a1) const { return std::make_pair(a0,a1); } }; } BOOST_PHOENIX_ADAPT_CALLABLE(make_pair, impl::make_pair, 2) } } int main() { namespace phx = boost::phoenix; using boost::phoenix::arg_names::arg1; using boost::phoenix::arg_names::arg2; int a = 99; int b = 256; std::pair ab1 = phx::make_pair(a,b)(); //std::cout << ab1.first << "," << ab1.second << std::endl; BOOST_TEST(ab1.first == 99 && ab1.second == 256); std::pair ab2 = phx::make_pair(arg1,b)(a); //std::cout << ab2.first << "," << ab2.second << std::endl; BOOST_TEST(ab2.first == 99 && ab2.second == 256); std::pair ab3 = phx::make_pair(arg1,arg2)(a,b); //std::cout << ab3.first << "," << ab3.second << std::endl; BOOST_TEST(ab3.first == 99 && ab3.second == 256); return boost::report_errors(); }