| Line | |
|---|
| 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 <cassert> |
|---|
| 8 | #include <boost/type.hpp> |
|---|
| 9 | |
|---|
| 10 | using boost::implicit_cast; |
|---|
| 11 | using boost::type; |
|---|
| 12 | |
|---|
| 13 | template <class T> |
|---|
| 14 | type<T> check_return(T) { return type<T>(); } |
|---|
| 15 | |
|---|
| 16 | struct foo |
|---|
| 17 | { |
|---|
| 18 | foo(char const*) {} |
|---|
| 19 | operator long() const { return 0; } |
|---|
| 20 | }; |
|---|
| 21 | |
|---|
| 22 | typedef type<long> long_type; |
|---|
| 23 | typedef type<foo> foo_type; |
|---|
| 24 | |
|---|
| 25 | int main() |
|---|
| 26 | { |
|---|
| 27 | type<long> x = check_return(boost::implicit_cast<long>(1)); |
|---|
| 28 | assert(boost::implicit_cast<long>(1) == 1L); |
|---|
| 29 | |
|---|
| 30 | type<foo> f = check_return(boost::implicit_cast<foo>("hello")); |
|---|
| 31 | type<long> z = check_return(boost::implicit_cast<long>(foo("hello"))); |
|---|
| 32 | return 0; |
|---|
| 33 | } |
|---|
Note: See
TracBrowser
for help on using the repository browser.