summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/hof/test/implicit.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/boost/libs/hof/test/implicit.cpp')
-rw-r--r--src/boost/libs/hof/test/implicit.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/boost/libs/hof/test/implicit.cpp b/src/boost/libs/hof/test/implicit.cpp
new file mode 100644
index 00000000..2f6624f4
--- /dev/null
+++ b/src/boost/libs/hof/test/implicit.cpp
@@ -0,0 +1,56 @@
+/*=============================================================================
+ Copyright (c) 2017 Paul Fultz II
+ implicit.cpp
+ 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/hof/implicit.hpp>
+#include "test.hpp"
+
+template<class T>
+struct auto_caster
+{
+ template<class U>
+ T operator()(U x)
+ {
+ return T(x);
+ }
+};
+
+template<class T>
+struct auto_caster_noexcept
+{
+ template<class U>
+ T operator()(U x) noexcept
+ {
+ return T(x);
+ }
+};
+
+struct auto_caster_foo
+{
+ int i;
+ explicit auto_caster_foo(int ip) : i(ip) {}
+
+};
+// TODO: Test template constraint on conversion operator
+static constexpr boost::hof::implicit<auto_caster> auto_cast = {};
+
+BOOST_HOF_TEST_CASE()
+{
+ float f = 1.5;
+ int i = auto_cast(f);
+ // auto_caster_foo x = 1;
+ auto_caster_foo x = auto_cast(1);
+ BOOST_HOF_TEST_CHECK(1 == i);
+ BOOST_HOF_TEST_CHECK(1 == x.i);
+
+}
+#if BOOST_HOF_HAS_NOEXCEPT_DEDUCTION
+BOOST_HOF_TEST_CASE()
+{
+ boost::hof::implicit<auto_caster_noexcept> lauto_cast{};
+ float f = 1.5;
+ static_assert(noexcept(int(lauto_cast(f))), "noexcept implicit");
+}
+#endif