diff options
Diffstat (limited to '')
-rw-r--r-- | src/boost/libs/hana/example/string/comparable.cpp | 20 | ||||
-rw-r--r-- | src/boost/libs/hana/example/string/foldable.cpp | 26 | ||||
-rw-r--r-- | src/boost/libs/hana/example/string/from_c_str.cpp | 20 | ||||
-rw-r--r-- | src/boost/libs/hana/example/string/hashable.cpp | 19 | ||||
-rw-r--r-- | src/boost/libs/hana/example/string/iterable.cpp | 26 | ||||
-rw-r--r-- | src/boost/libs/hana/example/string/literal.cpp | 28 | ||||
-rw-r--r-- | src/boost/libs/hana/example/string/macro.cpp | 17 | ||||
-rw-r--r-- | src/boost/libs/hana/example/string/make.cpp | 17 | ||||
-rw-r--r-- | src/boost/libs/hana/example/string/monoid.cpp | 15 | ||||
-rw-r--r-- | src/boost/libs/hana/example/string/orderable.cpp | 20 | ||||
-rw-r--r-- | src/boost/libs/hana/example/string/searchable.cpp | 21 | ||||
-rw-r--r-- | src/boost/libs/hana/example/string/string_c.cpp | 14 | ||||
-rw-r--r-- | src/boost/libs/hana/example/string/to.cpp | 21 |
13 files changed, 264 insertions, 0 deletions
diff --git a/src/boost/libs/hana/example/string/comparable.cpp b/src/boost/libs/hana/example/string/comparable.cpp new file mode 100644 index 000000000..e86d4bb0d --- /dev/null +++ b/src/boost/libs/hana/example/string/comparable.cpp @@ -0,0 +1,20 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include <boost/hana/assert.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/not_equal.hpp> +#include <boost/hana/string.hpp> +namespace hana = boost::hana; + + +int main() { + BOOST_HANA_CONSTANT_CHECK( + BOOST_HANA_STRING("abcdef") == BOOST_HANA_STRING("abcdef") + ); + + BOOST_HANA_CONSTANT_CHECK( + BOOST_HANA_STRING("abcdef") != BOOST_HANA_STRING("abef") + ); +} diff --git a/src/boost/libs/hana/example/string/foldable.cpp b/src/boost/libs/hana/example/string/foldable.cpp new file mode 100644 index 000000000..d1d4661ec --- /dev/null +++ b/src/boost/libs/hana/example/string/foldable.cpp @@ -0,0 +1,26 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include <boost/hana/assert.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/fold_left.hpp> +#include <boost/hana/integral_constant.hpp> +#include <boost/hana/plus.hpp> +#include <boost/hana/string.hpp> +#include <boost/hana/value.hpp> +namespace hana = boost::hana; + + +int main() { + auto sum_string = [](auto str) { + return hana::fold_left(str, hana::int_c<0>, [](auto sum, auto c) { + constexpr int i = hana::value(c) - 48; // convert character to decimal + return sum + hana::int_c<i>; + }); + }; + + BOOST_HANA_CONSTANT_CHECK( + sum_string(BOOST_HANA_STRING("1234")) == hana::int_c<1 + 2 + 3 + 4> + ); +} diff --git a/src/boost/libs/hana/example/string/from_c_str.cpp b/src/boost/libs/hana/example/string/from_c_str.cpp new file mode 100644 index 000000000..3441473ed --- /dev/null +++ b/src/boost/libs/hana/example/string/from_c_str.cpp @@ -0,0 +1,20 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include <boost/hana/assert.hpp> +#include <boost/hana/core/to.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/integral_constant.hpp> +#include <boost/hana/string.hpp> +namespace hana = boost::hana; + + +constexpr char const hello[] = "hello"; +auto hello_constant = hana::integral_constant<char const*, hello>{}; + +BOOST_HANA_CONSTANT_CHECK( + hana::to_string(hello_constant) == hana::string_c<'h', 'e', 'l', 'l', 'o'> +); + +int main() { } diff --git a/src/boost/libs/hana/example/string/hashable.cpp b/src/boost/libs/hana/example/string/hashable.cpp new file mode 100644 index 000000000..a781fdefc --- /dev/null +++ b/src/boost/libs/hana/example/string/hashable.cpp @@ -0,0 +1,19 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include <boost/hana/assert.hpp> +#include <boost/hana/hash.hpp> +#include <boost/hana/not_equal.hpp> +#include <boost/hana/string.hpp> +namespace hana = boost::hana; + + +// `hana::hash` returns a type uniquely representing the string. The hash is +// perfect, meaning no two different strings have the same hash value. +BOOST_HANA_CONSTANT_CHECK(hana::not_equal( + hana::hash(BOOST_HANA_STRING("abcdef")), + hana::hash(BOOST_HANA_STRING("abcdefg")) +)); + +int main() { } diff --git a/src/boost/libs/hana/example/string/iterable.cpp b/src/boost/libs/hana/example/string/iterable.cpp new file mode 100644 index 000000000..af7a2f383 --- /dev/null +++ b/src/boost/libs/hana/example/string/iterable.cpp @@ -0,0 +1,26 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include <boost/hana/assert.hpp> +#include <boost/hana/contains.hpp> +#include <boost/hana/drop_while.hpp> +#include <boost/hana/integral_constant.hpp> +#include <boost/hana/is_empty.hpp> +#include <boost/hana/string.hpp> +namespace hana = boost::hana; + + +int main() { + BOOST_HANA_CONSTANT_CHECK(!hana::is_empty(BOOST_HANA_STRING("abcd"))); + BOOST_HANA_CONSTANT_CHECK(hana::is_empty(BOOST_HANA_STRING(""))); + + BOOST_HANA_CONSTANT_CHECK(BOOST_HANA_STRING("abcd")[hana::size_c<2>] == hana::char_c<'c'>); + + auto is_vowel = [](auto c) { + return c ^hana::in^ BOOST_HANA_STRING("aeiouy"); + }; + BOOST_HANA_CONSTANT_CHECK( + hana::drop_while(BOOST_HANA_STRING("aioubcd"), is_vowel) == BOOST_HANA_STRING("bcd") + ); +} diff --git a/src/boost/libs/hana/example/string/literal.cpp b/src/boost/libs/hana/example/string/literal.cpp new file mode 100644 index 000000000..feab6f69e --- /dev/null +++ b/src/boost/libs/hana/example/string/literal.cpp @@ -0,0 +1,28 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include <boost/hana/assert.hpp> +#include <boost/hana/config.hpp> +#include <boost/hana/core/is_a.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/integral_constant.hpp> +#include <boost/hana/length.hpp> +#include <boost/hana/string.hpp> +namespace hana = boost::hana; +using namespace hana::literals; + + +// By default, this is disabled +#ifdef BOOST_HANA_CONFIG_ENABLE_STRING_UDL + + constexpr auto str = "Hello world!"_s; + BOOST_HANA_CONSTANT_CHECK(str == hana::string_c<'H', 'e', 'l', 'l', 'o', ' ', + 'w', 'o', 'r', 'l', 'd', '!'>); + + BOOST_HANA_CONSTANT_CHECK(hana::is_a<hana::string_tag>(str)); + BOOST_HANA_CONSTANT_CHECK(hana::length(str) == hana::size_c<12>); + +#endif + +int main() { } diff --git a/src/boost/libs/hana/example/string/macro.cpp b/src/boost/libs/hana/example/string/macro.cpp new file mode 100644 index 000000000..3c2d2ea7d --- /dev/null +++ b/src/boost/libs/hana/example/string/macro.cpp @@ -0,0 +1,17 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include <boost/hana/assert.hpp> +#include <boost/hana/config.hpp> +#include <boost/hana/core/is_a.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/string.hpp> +namespace hana = boost::hana; + + +int main() { + BOOST_HANA_CONSTEXPR_LAMBDA auto str = BOOST_HANA_STRING("abcdef"); + BOOST_HANA_CONSTANT_CHECK(str == hana::string_c<'a', 'b', 'c', 'd', 'e', 'f'>); + BOOST_HANA_CONSTANT_CHECK(hana::is_a<hana::string_tag>(str)); +} diff --git a/src/boost/libs/hana/example/string/make.cpp b/src/boost/libs/hana/example/string/make.cpp new file mode 100644 index 000000000..c7bac05d8 --- /dev/null +++ b/src/boost/libs/hana/example/string/make.cpp @@ -0,0 +1,17 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include <boost/hana/assert.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/string.hpp> +#include <boost/hana/tuple.hpp> +#include <boost/hana/unpack.hpp> +namespace hana = boost::hana; + + +constexpr auto vowels = hana::tuple_c<char, 'a', 'e', 'i', 'o', 'u', 'y'>; +constexpr auto str = hana::unpack(vowels, hana::make<hana::string_tag>); +BOOST_HANA_CONSTANT_CHECK(str == BOOST_HANA_STRING("aeiouy")); + +int main() { } diff --git a/src/boost/libs/hana/example/string/monoid.cpp b/src/boost/libs/hana/example/string/monoid.cpp new file mode 100644 index 000000000..305e6351f --- /dev/null +++ b/src/boost/libs/hana/example/string/monoid.cpp @@ -0,0 +1,15 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include <boost/hana/assert.hpp> +#include <boost/hana/equal.hpp> +#include <boost/hana/plus.hpp> +#include <boost/hana/string.hpp> +namespace hana = boost::hana; + + +auto hello_world = BOOST_HANA_STRING("Hello ") + BOOST_HANA_STRING("world!"); +BOOST_HANA_CONSTANT_CHECK(hello_world == BOOST_HANA_STRING("Hello world!")); + +int main() { } diff --git a/src/boost/libs/hana/example/string/orderable.cpp b/src/boost/libs/hana/example/string/orderable.cpp new file mode 100644 index 000000000..21faeaa27 --- /dev/null +++ b/src/boost/libs/hana/example/string/orderable.cpp @@ -0,0 +1,20 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include <boost/hana/assert.hpp> +#include <boost/hana/greater.hpp> +#include <boost/hana/less.hpp> +#include <boost/hana/string.hpp> +namespace hana = boost::hana; + + +int main() { + BOOST_HANA_CONSTANT_CHECK( + BOOST_HANA_STRING("abc") < BOOST_HANA_STRING("bcd") + ); + + BOOST_HANA_CONSTANT_CHECK( + BOOST_HANA_STRING("abcd") > BOOST_HANA_STRING("abc") + ); +} diff --git a/src/boost/libs/hana/example/string/searchable.cpp b/src/boost/libs/hana/example/string/searchable.cpp new file mode 100644 index 000000000..b7e2175af --- /dev/null +++ b/src/boost/libs/hana/example/string/searchable.cpp @@ -0,0 +1,21 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include <boost/hana/assert.hpp> +#include <boost/hana/contains.hpp> +#include <boost/hana/find.hpp> +#include <boost/hana/integral_constant.hpp> +#include <boost/hana/optional.hpp> +#include <boost/hana/string.hpp> +namespace hana = boost::hana; + + +int main() { + BOOST_HANA_CONSTANT_CHECK(hana::char_c<'c'> ^hana::in^ BOOST_HANA_STRING("abcde")); + BOOST_HANA_CONSTANT_CHECK(!(hana::char_c<'z'> ^hana::in^ BOOST_HANA_STRING("abcde"))); + + BOOST_HANA_CONSTANT_CHECK( + hana::find(BOOST_HANA_STRING("abcxefg"), hana::char_c<'x'>) == hana::just(hana::char_c<'x'>) + ); +} diff --git a/src/boost/libs/hana/example/string/string_c.cpp b/src/boost/libs/hana/example/string/string_c.cpp new file mode 100644 index 000000000..327234078 --- /dev/null +++ b/src/boost/libs/hana/example/string/string_c.cpp @@ -0,0 +1,14 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include <boost/hana/assert.hpp> +#include <boost/hana/core/is_a.hpp> +#include <boost/hana/string.hpp> +namespace hana = boost::hana; + + +constexpr auto str = hana::string_c<'a', 'b', 'c', 'd', 'e', 'f'>; +BOOST_HANA_CONSTANT_CHECK(hana::is_a<hana::string_tag>(str)); + +int main() { } diff --git a/src/boost/libs/hana/example/string/to.cpp b/src/boost/libs/hana/example/string/to.cpp new file mode 100644 index 000000000..16109a235 --- /dev/null +++ b/src/boost/libs/hana/example/string/to.cpp @@ -0,0 +1,21 @@ +// Copyright Louis Dionne 2013-2017 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include <boost/hana/assert.hpp> +#include <boost/hana/core/to.hpp> +#include <boost/hana/string.hpp> +namespace hana = boost::hana; + + +constexpr auto str = hana::string_c<'h', 'i'>; + +// using c_str() +constexpr char const* s1 = str.c_str(); +static_assert(s1[0] == 'h' && s1[1] == 'i' && s1[2] == '\0', ""); + +// using hana::to +constexpr char const* s2 = hana::to<char const*>(str); +static_assert(s2[0] == 'h' && s2[1] == 'i' && s2[2] == '\0', ""); + +int main() { } |