Files
conversion/test/implicit_cast.cpp
T

43 lines
1022 B
C++
Raw Normal View History

// 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; }
};
2024-12-17 16:37:40 +03:00
using long_type = type<long>;
using foo_type = type<foo>;
2003-05-07 20:41:11 +00:00
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")));
2015-01-30 15:22:27 -07:00
// warning suppression:
2009-11-09 12:27:54 +00:00
(void)x;
(void)f;
(void)z;
2023-08-10 18:52:03 +03:00
constexpr long value = boost::implicit_cast<long>(42);
BOOST_TEST(value == 42L);
2006-02-28 22:56:33 +00:00
return boost::report_errors();
2003-05-07 20:41:11 +00:00
}