2004-07-26 00:32:12 +00:00
|
|
|
// Copyright David Abrahams 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)
|
2003-05-07 20:41:11 +00:00
|
|
|
|
|
|
|
|
#include <boost/implicit_cast.hpp>
|
2006-02-28 22:56:33 +00:00
|
|
|
#include <boost/detail/lightweight_test.hpp>
|
2003-05-07 20:41:11 +00:00
|
|
|
#include <boost/type.hpp>
|
|
|
|
|
using boost::implicit_cast;
|
|
|
|
|
using boost::type;
|
|
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
|
type<T> check_return(T) { return type<T>(); }
|
|
|
|
|
|
|
|
|
|
struct foo
|
|
|
|
|
{
|
|
|
|
|
foo(char const*) {}
|
|
|
|
|
operator long() const { return 0; }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef type<long> long_type;
|
|
|
|
|
typedef type<foo> foo_type;
|
|
|
|
|
|
|
|
|
|
int main()
|
|
|
|
|
{
|
|
|
|
|
type<long> x = check_return(boost::implicit_cast<long>(1));
|
2006-02-28 22:56:33 +00:00
|
|
|
BOOST_TEST(boost::implicit_cast<long>(1) == 1L);
|
2003-05-07 20:41:11 +00:00
|
|
|
|
|
|
|
|
type<foo> f = check_return(boost::implicit_cast<foo>("hello"));
|
|
|
|
|
type<long> z = check_return(boost::implicit_cast<long>(foo("hello")));
|
2012-05-20 16:25:21 +00:00
|
|
|
|
2015-01-30 15:22:27 -07:00
|
|
|
// warning suppression:
|
2009-11-09 12:27:54 +00:00
|
|
|
(void)x;
|
|
|
|
|
(void)f;
|
|
|
|
|
(void)z;
|
|
|
|
|
|
2021-04-21 20:51:14 +03:00
|
|
|
|
2023-08-10 18:52:03 +03:00
|
|
|
constexpr long value = boost::implicit_cast<long>(42);
|
2021-04-21 20:51:14 +03:00
|
|
|
BOOST_TEST(value == 42L);
|
|
|
|
|
|
2006-02-28 22:56:33 +00:00
|
|
|
return boost::report_errors();
|
2003-05-07 20:41:11 +00:00
|
|
|
}
|