to.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. #include <boost/hana/assert.hpp>
  5. #include <boost/hana/core/to.hpp>
  6. #include <boost/hana/string.hpp>
  7. #include <cstring>
  8. namespace hana = boost::hana;
  9. static_assert(hana::is_convertible<hana::string_tag, char const*>{}, "");
  10. static_assert(!hana::is_embedded<hana::string_tag, char const*>{}, "");
  11. int main() {
  12. BOOST_HANA_RUNTIME_CHECK(std::strcmp(
  13. hana::to<char const*>(BOOST_HANA_STRING("")),
  14. ""
  15. ) == 0);
  16. BOOST_HANA_RUNTIME_CHECK(std::strcmp(
  17. hana::to<char const*>(BOOST_HANA_STRING("a")),
  18. "a"
  19. ) == 0);
  20. BOOST_HANA_RUNTIME_CHECK(std::strcmp(
  21. hana::to<char const*>(BOOST_HANA_STRING("ab")),
  22. "ab"
  23. ) == 0);
  24. BOOST_HANA_RUNTIME_CHECK(std::strcmp(
  25. hana::to<char const*>(BOOST_HANA_STRING("abc")),
  26. "abc"
  27. ) == 0);
  28. BOOST_HANA_RUNTIME_CHECK(std::strcmp(
  29. hana::to<char const*>(BOOST_HANA_STRING("abcd")),
  30. "abcd"
  31. ) == 0);
  32. // make sure we can turn a non-constexpr hana::string
  33. // into a constexpr char const*
  34. auto str = BOOST_HANA_STRING("abcdef");
  35. constexpr char const* c_str = hana::to<char const*>(str);
  36. (void)c_str;
  37. }