1 // Copyright Louis Dionne 2013-2017
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
4
5 #include <boost/hana/assert.hpp>
6 #include <boost/hana/core/to.hpp>
7 #include <boost/hana/equal.hpp>
8 #include <boost/hana/ext/std/integral_constant.hpp>
9 #include <boost/hana/integral_constant.hpp>
10 #include <boost/hana/string.hpp>
11
12 #include <type_traits>
13 namespace hana = boost::hana;
14
15
16 constexpr char const empty[] = "";
17 constexpr char const a[] = "a";
18 constexpr char const ab[] = "ab";
19 constexpr char const abc[] = "abc";
20 constexpr char const abcd[] = "abcd";
21
main()22 int main() {
23 {
24 auto string = hana::to<hana::string_tag>(hana::integral_constant<char const*, empty>{});
25 BOOST_HANA_CONSTANT_CHECK(hana::equal(string, hana::string_c<>));
26 }
27
28 {
29 auto string = hana::to<hana::string_tag>(hana::integral_constant<char const*, a>{});
30 BOOST_HANA_CONSTANT_CHECK(hana::equal(string, hana::string_c<'a'>));
31 }
32
33 {
34 auto string = hana::to<hana::string_tag>(hana::integral_constant<char const*, ab>{});
35 BOOST_HANA_CONSTANT_CHECK(hana::equal(string, hana::string_c<'a', 'b'>));
36 }
37
38 {
39 auto string = hana::to<hana::string_tag>(hana::integral_constant<char const*, abc>{});
40 BOOST_HANA_CONSTANT_CHECK(hana::equal(string, hana::string_c<'a', 'b', 'c'>));
41 }
42
43 {
44 auto string = hana::to<hana::string_tag>(hana::integral_constant<char const*, abcd>{});
45 BOOST_HANA_CONSTANT_CHECK(hana::equal(string, hana::string_c<'a', 'b', 'c', 'd'>));
46 }
47
48 // Make sure it also works with std::integral_constant, for example
49 {
50 auto string = hana::to<hana::string_tag>(std::integral_constant<char const*, abcd>{});
51 BOOST_HANA_CONSTANT_CHECK(hana::equal(string, hana::string_c<'a', 'b', 'c', 'd'>));
52 }
53
54 // Make sure the `to_string` shortcut works
55 {
56 auto string = hana::to_string(hana::integral_constant<char const*, abcd>{});
57 BOOST_HANA_CONSTANT_CHECK(hana::equal(string, hana::string_c<'a', 'b', 'c', 'd'>));
58 }
59 }
60