123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438 |
- /*==============================================================================
- Copyright (c) 2004, 2005, 2009 Peter Dimov
- Copyright (c) 2005-2010 Joel de Guzman
- Copyright (c) 2010 Thomas Heller
- 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 <boost/config.hpp>
- #if defined(BOOST_MSVC)
- #pragma warning(disable: 4786) // identifier truncated in debug info
- #pragma warning(disable: 4710) // function not inlined
- #pragma warning(disable: 4711) // function selected for automatic inline expansion
- #pragma warning(disable: 4514) // unreferenced inline removed
- #endif
- #include <boost/phoenix/core.hpp>
- #include <boost/phoenix/bind.hpp>
- #ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
- # include <boost/function_equal.hpp>
- #endif
- #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
- #pragma warning(push, 3)
- #endif
- #include <iostream>
- #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
- #pragma warning(pop)
- #endif
- #include <boost/detail/lightweight_test.hpp>
- struct X
- {
- int i_;
- explicit X(int i): i_(i)
- {
- }
- bool operator==(X const & rhs) const
- {
- return i_ == rhs.i_;
- }
- };
- // f_*
- int f_0()
- {
- return 0;
- }
- int f_1(X)
- {
- return 0;
- }
- int f_2(X, X)
- {
- return 0;
- }
- int f_3(X, X, X)
- {
- return 0;
- }
- int f_4(X, X, X, X)
- {
- return 0;
- }
- int f_5(X, X, X, X, X)
- {
- return 0;
- }
- int f_6(X, X, X, X, X, X)
- {
- return 0;
- }
- int f_7(X, X, X, X, X, X, X)
- {
- return 0;
- }
- int f_8(X, X, X, X, X, X, X, X)
- {
- return 0;
- }
- int f_9(X, X, X, X, X, X, X, X, X)
- {
- return 0;
- }
- // fv_*
- void fv_0()
- {
- }
- void fv_1(X)
- {
- }
- void fv_2(X, X)
- {
- }
- void fv_3(X, X, X)
- {
- }
- void fv_4(X, X, X, X)
- {
- }
- void fv_5(X, X, X, X, X)
- {
- }
- void fv_6(X, X, X, X, X, X)
- {
- }
- void fv_7(X, X, X, X, X, X, X)
- {
- }
- void fv_8(X, X, X, X, X, X, X, X)
- {
- }
- void fv_9(X, X, X, X, X, X, X, X, X)
- {
- }
- template<class F> void test_eq(F f1, F f2)
- {
- #ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
- using boost::function_equal;
- #endif
- BOOST_TEST( function_equal( f1, f2 ) );
- }
- template<class F> void test_ne(F f1, F f2)
- {
- #ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
- using boost::function_equal;
- #endif
- BOOST_TEST( !function_equal( f1, f2 ) );
- }
-
- using boost::phoenix::bind;
- using boost::phoenix::ref;
- using boost::phoenix::placeholders::_1;
- using boost::phoenix::placeholders::_2;
- using boost::phoenix::placeholders::_3;
- using boost::phoenix::placeholders::_4;
- using boost::phoenix::placeholders::_5;
- using boost::phoenix::placeholders::_6;
- using boost::phoenix::placeholders::_7;
- using boost::phoenix::placeholders::_8;
- using boost::phoenix::placeholders::_9;
- // 0
- template<class F> void test_0(F f)
- {
- test_eq( bind(f), bind(f) );
- }
- // 1
- template<class F, class V> void test_1_(F f, V v1, V v2)
- {
- test_eq( bind(f, v1), bind(f, v1) );
- test_ne( bind(f, v1), bind(f, v2) );
- }
- template<class F> void test_1(F f)
- {
- test_eq( bind(f, _1), bind(f, _1) );
- test_1_( f, X(1), X(2) );
- X a(0), b(0);
- test_1_( f, ref(a), ref(b) );
- }
- // 2
- template<class F, class V> void test_2_(F f, V v1, V v2)
- {
- test_eq( bind(f, v1, v1), bind(f, v1, v1) );
- test_ne( bind(f, v1, v1), bind(f, v1, v2) );
- test_ne( bind(f, v1, v1), bind(f, v2, v1) );
- }
- template<class F> void test_2(F f)
- {
- test_eq( bind(f, _1, _2), bind(f, _1, _2) );
- test_2_( f, X(1), X(2) );
- X a(0), b(0);
- test_2_( f, ref(a), ref(b) );
- }
- // 3
- template<class F, class V> void test_3_(F f, V v1, V v2)
- {
- test_eq( bind(f, v1, v1, v1), bind(f, v1, v1, v1) );
- test_ne( bind(f, v1, v1, v1), bind(f, v1, v1, v2) );
- test_ne( bind(f, v1, v1, v1), bind(f, v1, v2, v1) );
- test_ne( bind(f, v1, v1, v1), bind(f, v2, v1, v1) );
- }
- template<class F> void test_3(F f)
- {
- test_eq( bind(f, _1, _2, _3), bind(f, _1, _2, _3) );
- test_3_( f, X(1), X(2) );
- X a(0), b(0);
- test_3_( f, ref(a), ref(b) );
- }
- // 4
- template<class F, class V> void test_4_(F f, V v1, V v2)
- {
- test_eq( bind(f, v1, v1, v1, v1), bind(f, v1, v1, v1, v1) );
- test_ne( bind(f, v1, v1, v1, v1), bind(f, v1, v1, v1, v2) );
- test_ne( bind(f, v1, v1, v1, v1), bind(f, v1, v1, v2, v1) );
- test_ne( bind(f, v1, v1, v1, v1), bind(f, v1, v2, v1, v1) );
- test_ne( bind(f, v1, v1, v1, v1), bind(f, v2, v1, v1, v1) );
- }
- template<class F> void test_4(F f)
- {
- test_eq( bind(f, _1, _2, _3, _4), bind(f, _1, _2, _3, _4) );
- test_4_( f, X(1), X(2) );
- X a(0), b(0);
- test_4_( f, ref(a), ref(b) );
- }
- // 5
- template<class F, class V> void test_5_(F f, V v1, V v2)
- {
- test_eq( bind(f, v1, v1, v1, v1, v1), bind(f, v1, v1, v1, v1, v1) );
- test_ne( bind(f, v1, v1, v1, v1, v1), bind(f, v1, v1, v1, v1, v2) );
- test_ne( bind(f, v1, v1, v1, v1, v1), bind(f, v1, v1, v1, v2, v1) );
- test_ne( bind(f, v1, v1, v1, v1, v1), bind(f, v1, v1, v2, v1, v1) );
- test_ne( bind(f, v1, v1, v1, v1, v1), bind(f, v1, v2, v1, v1, v1) );
- test_ne( bind(f, v1, v1, v1, v1, v1), bind(f, v2, v1, v1, v1, v1) );
- }
- template<class F> void test_5(F f)
- {
- test_eq( bind(f, _1, _2, _3, _4, _5), bind(f, _1, _2, _3, _4, _5) );
- test_5_( f, X(1), X(2) );
- X a(0), b(0);
- test_5_( f, ref(a), ref(b) );
- }
- // 6
- template<class F, class V> void test_6_(F f, V v1, V v2)
- {
- test_eq( bind(f, v1, v1, v1, v1, v1, v1), bind(f, v1, v1, v1, v1, v1, v1) );
- test_ne( bind(f, v1, v1, v1, v1, v1, v1), bind(f, v1, v1, v1, v1, v1, v2) );
- test_ne( bind(f, v1, v1, v1, v1, v1, v1), bind(f, v1, v1, v1, v1, v2, v1) );
- test_ne( bind(f, v1, v1, v1, v1, v1, v1), bind(f, v1, v1, v1, v2, v1, v1) );
- test_ne( bind(f, v1, v1, v1, v1, v1, v1), bind(f, v1, v1, v2, v1, v1, v1) );
- test_ne( bind(f, v1, v1, v1, v1, v1, v1), bind(f, v1, v2, v1, v1, v1, v1) );
- test_ne( bind(f, v1, v1, v1, v1, v1, v1), bind(f, v2, v1, v1, v1, v1, v1) );
- }
- template<class F> void test_6(F f)
- {
- test_eq( bind(f, _1, _2, _3, _4, _5, _6), bind(f, _1, _2, _3, _4, _5, _6) );
- test_6_( f, X(1), X(2) );
- X a(0), b(0);
- test_6_( f, ref(a), ref(b) );
- }
- // 7
- template<class F, class V> void test_7_(F f, V v1, V v2)
- {
- test_eq( bind(f, v1, v1, v1, v1, v1, v1, v1), bind(f, v1, v1, v1, v1, v1, v1, v1) );
- test_ne( bind(f, v1, v1, v1, v1, v1, v1, v1), bind(f, v1, v1, v1, v1, v1, v1, v2) );
- test_ne( bind(f, v1, v1, v1, v1, v1, v1, v1), bind(f, v1, v1, v1, v1, v1, v2, v1) );
- test_ne( bind(f, v1, v1, v1, v1, v1, v1, v1), bind(f, v1, v1, v1, v1, v2, v1, v1) );
- test_ne( bind(f, v1, v1, v1, v1, v1, v1, v1), bind(f, v1, v1, v1, v2, v1, v1, v1) );
- test_ne( bind(f, v1, v1, v1, v1, v1, v1, v1), bind(f, v1, v1, v2, v1, v1, v1, v1) );
- test_ne( bind(f, v1, v1, v1, v1, v1, v1, v1), bind(f, v1, v2, v1, v1, v1, v1, v1) );
- test_ne( bind(f, v1, v1, v1, v1, v1, v1, v1), bind(f, v2, v1, v1, v1, v1, v1, v1) );
- }
- template<class F> void test_7(F f)
- {
- test_eq( bind(f, _1, _2, _3, _4, _5, _6, _7), bind(f, _1, _2, _3, _4, _5, _6, _7) );
- test_7_( f, X(1), X(2) );
- X a(0), b(0);
- test_7_( f, ref(a), ref(b) );
- }
- // 8
- template<class F, class V> void test_8_(F f, V v1, V v2)
- {
- test_eq( bind(f, v1, v1, v1, v1, v1, v1, v1, v1), bind(f, v1, v1, v1, v1, v1, v1, v1, v1) );
- test_ne( bind(f, v1, v1, v1, v1, v1, v1, v1, v1), bind(f, v1, v1, v1, v1, v1, v1, v1, v2) );
- test_ne( bind(f, v1, v1, v1, v1, v1, v1, v1, v1), bind(f, v1, v1, v1, v1, v1, v1, v2, v1) );
- test_ne( bind(f, v1, v1, v1, v1, v1, v1, v1, v1), bind(f, v1, v1, v1, v1, v1, v2, v1, v1) );
- test_ne( bind(f, v1, v1, v1, v1, v1, v1, v1, v1), bind(f, v1, v1, v1, v1, v2, v1, v1, v1) );
- test_ne( bind(f, v1, v1, v1, v1, v1, v1, v1, v1), bind(f, v1, v1, v1, v2, v1, v1, v1, v1) );
- test_ne( bind(f, v1, v1, v1, v1, v1, v1, v1, v1), bind(f, v1, v1, v2, v1, v1, v1, v1, v1) );
- test_ne( bind(f, v1, v1, v1, v1, v1, v1, v1, v1), bind(f, v1, v2, v1, v1, v1, v1, v1, v1) );
- test_ne( bind(f, v1, v1, v1, v1, v1, v1, v1, v1), bind(f, v2, v1, v1, v1, v1, v1, v1, v1) );
- }
- template<class F> void test_8(F f)
- {
- test_eq( bind(f, _1, _2, _3, _4, _5, _6, _7, _8), bind(f, _1, _2, _3, _4, _5, _6, _7, _8) );
- test_8_( f, X(1), X(2) );
- X a(0), b(0);
- test_8_( f, ref(a), ref(b) );
- }
- // 9
- template<class F, class V> void test_9_(F f, V v1, V v2)
- {
- test_eq( bind(f, v1, v1, v1, v1, v1, v1, v1, v1, v1), bind(f, v1, v1, v1, v1, v1, v1, v1, v1, v1) );
- test_ne( bind(f, v1, v1, v1, v1, v1, v1, v1, v1, v1), bind(f, v1, v1, v1, v1, v1, v1, v1, v1, v2) );
- test_ne( bind(f, v1, v1, v1, v1, v1, v1, v1, v1, v1), bind(f, v1, v1, v1, v1, v1, v1, v1, v2, v1) );
- test_ne( bind(f, v1, v1, v1, v1, v1, v1, v1, v1, v1), bind(f, v1, v1, v1, v1, v1, v1, v2, v1, v1) );
- test_ne( bind(f, v1, v1, v1, v1, v1, v1, v1, v1, v1), bind(f, v1, v1, v1, v1, v1, v2, v1, v1, v1) );
- test_ne( bind(f, v1, v1, v1, v1, v1, v1, v1, v1, v1), bind(f, v1, v1, v1, v1, v2, v1, v1, v1, v1) );
- test_ne( bind(f, v1, v1, v1, v1, v1, v1, v1, v1, v1), bind(f, v1, v1, v1, v2, v1, v1, v1, v1, v1) );
- test_ne( bind(f, v1, v1, v1, v1, v1, v1, v1, v1, v1), bind(f, v1, v1, v2, v1, v1, v1, v1, v1, v1) );
- test_ne( bind(f, v1, v1, v1, v1, v1, v1, v1, v1, v1), bind(f, v1, v2, v1, v1, v1, v1, v1, v1, v1) );
- test_ne( bind(f, v1, v1, v1, v1, v1, v1, v1, v1, v1), bind(f, v2, v1, v1, v1, v1, v1, v1, v1, v1) );
- }
- template<class F> void test_9(F f)
- {
- test_eq( bind(f, _1, _2, _3, _4, _5, _6, _7, _8, _9), bind(f, _1, _2, _3, _4, _5, _6, _7, _8, _9) );
- test_9_( f, X(1), X(2) );
- X a(0), b(0);
- test_9_( f, ref(a), ref(b) );
- }
- int main()
- {
- // 0
- test_0( f_0 );
- test_0( fv_0 );
- // 1
- test_1( f_1 );
- test_1( fv_1 );
- // 2
- test_2( f_2 );
- test_2( fv_2 );
- // 3
- test_3( f_3 );
- test_3( fv_3 );
- // 4
- test_4( f_4 );
- test_4( fv_4 );
- // 5
- test_5( f_5 );
- test_5( fv_5 );
- // 6
- test_6( f_6 );
- test_6( fv_6 );
- // 7
- test_7( f_7 );
- test_7( fv_7 );
- // 8
- test_8( f_8 );
- test_8( fv_8 );
- // 9
- test_9( f_9 );
- test_9( fv_9 );
- return boost::report_errors();
- }
|