]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/boost/libs/parameter/test/sfinae.cpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / libs / parameter / test / sfinae.cpp
index f017a21f7022cf8962705407d42cad295da13a9a..eb325e0f6b3e60b524bae82c9b79b2c496d86b8f 100644 (file)
-// Copyright David Abrahams, Daniel Wallin 2003. Use, modification and 
-// distribution is subject to 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
+// Copyright David Abrahams, Daniel Wallin 2003.
+// 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/parameter.hpp>
-#include <boost/parameter/match.hpp>
-#include <boost/detail/lightweight_test.hpp>
-#include <string>
+#include <boost/parameter/config.hpp>
+
+#if (BOOST_PARAMETER_MAX_ARITY < 2)
+#error Define BOOST_PARAMETER_MAX_ARITY as 2 or greater.
+#endif
+#if !defined(BOOST_PARAMETER_HAS_PERFECT_FORWARDING)
+#if (BOOST_PARAMETER_EXPONENTIAL_OVERLOAD_THRESHOLD_ARITY < 3)
+#error Define BOOST_PARAMETER_EXPONENTIAL_OVERLOAD_THRESHOLD_ARITY \
+as 3 or greater.
+#endif
+#endif
+
+#include <boost/parameter/name.hpp>
+
+namespace test {
+
+    BOOST_PARAMETER_NAME((name, keywords) in(name))
+    BOOST_PARAMETER_NAME((value, keywords) in(value))
+} // namespace test
+
+#if defined(BOOST_PARAMETER_CAN_USE_MP11)
+#include <type_traits>
+#else
+#include <boost/mpl/bool.hpp>
+#include <boost/mpl/if.hpp>
 #include <boost/type_traits/is_convertible.hpp>
+#endif
 
-#if ! defined(BOOST_NO_SFINAE) && ! BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x592))
-# include <boost/utility/enable_if.hpp>
-# include <boost/type_traits/is_same.hpp>
-#endif 
+namespace test {
 
-namespace test
-{
-  BOOST_PARAMETER_KEYWORD(keywords,name)
-  BOOST_PARAMETER_KEYWORD(keywords,value)
-  
-  using namespace boost::parameter;
-
-  struct f_parameters
-    : parameters<
-          optional<
-              keywords::name
-            , boost::is_convertible<boost::mpl::_, std::string>
-          >
-        , optional<
-              keywords::value
-            , boost::is_convertible<boost::mpl::_, float>
-          >
-      >
-  {};
-
-  // The use of assert_equal_string is just a nasty workaround for a
-  // vc++ 6 ICE.
-  void assert_equal_string(std::string x, std::string y)
-  {
+    template <typename To>
+    struct f_predicate
+    {
+        template <typename From, typename Args>
+#if defined(BOOST_PARAMETER_CAN_USE_MP11)
+        using fn = std::is_convertible<From,To>;
+#else
+        struct apply
+          : boost::mpl::if_<
+                boost::is_convertible<From,To>
+              , boost::mpl::true_
+              , boost::mpl::false_
+            >
+        {
+        };
+#endif
+    };
+} // namespace test
+
+#include <boost/parameter/parameters.hpp>
+#include <boost/parameter/optional.hpp>
+#include <string>
+
+namespace test {
+
+    struct f_parameters
+      : boost::parameter::parameters<
+            boost::parameter::optional<
+                test::keywords::name
+              , test::f_predicate<std::string>
+            >
+          , boost::parameter::optional<
+                test::keywords::value
+              , test::f_predicate<float>
+            >
+        >
+    {
+    };
+} // namespace test
+
+#include <boost/core/lightweight_test.hpp>
+
+namespace test {
+
+    // The use of assert_equal_string is just a nasty workaround for a
+    // vc++ 6 ICE.
+    void assert_equal_string(std::string x, std::string y)
+    {
         BOOST_TEST(x == y);
-  }
-  
-  template<class P>
-  void f_impl(P const& p)
-  {
-      float v = p[value | 3.f];
-      BOOST_TEST(v == 3.f);
-      assert_equal_string(p[name | "bar"], "foo");
-  }
-
-  void f()
-  {
-      f_impl(f_parameters()());
-  }
-
-  template<class A0>
-  void f(
-      A0 const& a0
-    , BOOST_PARAMETER_MATCH(f_parameters, (A0), args))
-  {
-      f_impl(args(a0));
-  }
-
-  template<class A0, class A1>
-  void f(
-      A0 const& a0, A1 const& a1
-    , BOOST_PARAMETER_MATCH(f_parameters,(A0)(A1), args))
-  {
-      f_impl(args(a0, a1));
-  }
-
-#if ! defined(BOOST_NO_SFINAE) && ! BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x592))
-  // On compilers that actually support SFINAE, add another overload
-  // that is an equally good match and can only be in the overload set
-  // when the others are not.  This tests that the SFINAE is actually
-  // working.  On all other compilers we're just checking that
-  // everything about SFINAE-enabled code will work, except of course
-  // the SFINAE.
-  template<class A0, class A1>
-  typename boost::enable_if<boost::is_same<int,A0>, int>::type
-  f(A0 const& a0, A1 const& a1)
-  {
-      return 0;
-  }
-#endif 
+    }
+
+    template <typename P>
+    void f_impl(P const& p)
+    {
+        float v = p[test::value | 3.f];
+        BOOST_TEST_EQ(v, 3.f);
+        test::assert_equal_string(p[test::name | "bar"], "foo");
+    }
+
+    void f()
+    {
+        test::f_impl(f_parameters()());
+    }
 } // namespace test
 
-int main()
-{
-    using test::name;
-    using test::value;    
-    using test::f;
+#include <boost/parameter/match.hpp>
+
+namespace test {
+
+    template <typename A0>
+    void
+        f(
+            A0 const& a0
+          , BOOST_PARAMETER_MATCH(f_parameters, (A0), args)
+        )
+    {
+        test::f_impl(args(a0));
+    }
+
+    template <typename A0, typename A1>
+    void
+        f(
+            A0 const& a0
+          , A1 const& a1
+          , BOOST_PARAMETER_MATCH(f_parameters, (A0)(A1), args)
+        )
+    {
+        test::f_impl(args(a0, a1));
+    }
+} // namespace test
+
+#if !defined(BOOST_NO_SFINAE) && \
+    !BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x592))
+#include <boost/core/enable_if.hpp>
+
+#if !defined(BOOST_PARAMETER_CAN_USE_MP11)
+#include <boost/type_traits/is_same.hpp>
+#endif
+
+namespace test {
 
-    f("foo");
-    f("foo", 3.f);
-    f(value = 3.f, name = "foo");
+    // On compilers that actually support SFINAE, add another overload that is
+    // an equally good match and can only be in the overload set when the
+    // others are not.  This tests that the SFINAE is actually working.  On
+    // all other compilers we're just checking that everything about
+    // SFINAE-enabled code will work, except of course the SFINAE.
+    template <typename A0, typename A1>
+    typename boost::enable_if<
+#if defined(BOOST_PARAMETER_CAN_USE_MP11)
+        std::is_same<int,A0>
+#else
+        typename boost::mpl::if_<
+            boost::is_same<int,A0>
+          , boost::mpl::true_
+          , boost::mpl::false_
+        >::type
+#endif
+      , int
+    >::type
+        f(A0 const& a0, A1 const& a1)
+    {
+        return 0;
+    }
+} // namespace test
+
+#endif  // SFINAE enabled, no Borland workarounds needed.
 
-#if ! defined(BOOST_NO_SFINAE) && ! BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x592))
-    BOOST_TEST(f(3, 4) == 0);
+int main()
+{
+    test::f("foo");
+    test::f("foo", 3.f);
+    test::f(test::value = 3.f, test::name = "foo");
+#if !defined(BOOST_NO_SFINAE) && \
+    !BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x592))
+    BOOST_TEST_EQ(0, test::f(3, 4));
 #endif
     return boost::report_errors();
 }