c_str.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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/string.hpp>
  6. #include <cstring>
  7. namespace hana = boost::hana;
  8. int main() {
  9. BOOST_HANA_RUNTIME_CHECK(std::strcmp(
  10. BOOST_HANA_STRING("").c_str(),
  11. ""
  12. ) == 0);
  13. BOOST_HANA_RUNTIME_CHECK(std::strcmp(
  14. BOOST_HANA_STRING("a").c_str(),
  15. "a"
  16. ) == 0);
  17. BOOST_HANA_RUNTIME_CHECK(std::strcmp(
  18. BOOST_HANA_STRING("ab").c_str(),
  19. "ab"
  20. ) == 0);
  21. BOOST_HANA_RUNTIME_CHECK(std::strcmp(
  22. BOOST_HANA_STRING("abc").c_str(),
  23. "abc"
  24. ) == 0);
  25. BOOST_HANA_RUNTIME_CHECK(std::strcmp(
  26. BOOST_HANA_STRING("abcd").c_str(),
  27. "abcd"
  28. ) == 0);
  29. // make sure we can turn a non-constexpr hana::string
  30. // into a constexpr char const*
  31. {
  32. auto str = BOOST_HANA_STRING("abcdef");
  33. constexpr char const* c_str = str.c_str();
  34. (void)c_str;
  35. }
  36. // make sure c_str is actually a static member function
  37. {
  38. constexpr char const* c_str = hana::string<'f', 'o', 'o'>::c_str();
  39. (void)c_str;
  40. }
  41. }