Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/libs/conversion/test/implicit_cast.cpp @ 12

Last change on this file since 12 was 12, checked in by landauf, 18 years ago

added boost

File size: 812 bytes
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
10using boost::implicit_cast;
11using boost::type;
12
13template <class T>
14type<T> check_return(T) { return type<T>(); }
15
16struct foo
17{
18    foo(char const*) {}
19    operator long() const { return 0; }
20};
21
22typedef type<long> long_type;
23typedef type<foo> foo_type;
24
25int 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.