]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // Copyright David Abrahams 2003. |
2 | // Distributed under the Boost Software License, Version 1.0. (See | |
3 | // accompanying file LICENSE_1_0.txt or copy at | |
4 | // http://www.boost.org/LICENSE_1_0.txt) | |
5 | ||
6 | #include <boost/implicit_cast.hpp> | |
7 | #include <boost/detail/lightweight_test.hpp> | |
8 | #include <boost/type.hpp> | |
9 | using boost::implicit_cast; | |
10 | using boost::type; | |
11 | ||
12 | template <class T> | |
13 | type<T> check_return(T) { return type<T>(); } | |
14 | ||
15 | struct foo | |
16 | { | |
17 | foo(char const*) {} | |
18 | operator long() const { return 0; } | |
19 | }; | |
20 | ||
21 | typedef type<long> long_type; | |
22 | typedef type<foo> foo_type; | |
23 | ||
24 | int main() | |
25 | { | |
26 | type<long> x = check_return(boost::implicit_cast<long>(1)); | |
27 | BOOST_TEST(boost::implicit_cast<long>(1) == 1L); | |
28 | ||
29 | type<foo> f = check_return(boost::implicit_cast<foo>("hello")); | |
30 | type<long> z = check_return(boost::implicit_cast<long>(foo("hello"))); | |
31 | ||
32 | // warning suppression: | |
33 | (void)x; | |
34 | (void)f; | |
35 | (void)z; | |
36 | ||
1e59de90 TL |
37 | |
38 | BOOST_CONSTEXPR long value = boost::implicit_cast<long>(42); | |
39 | BOOST_TEST(value == 42L); | |
40 | ||
7c673cae FG |
41 | return boost::report_errors(); |
42 | } |