Last active
November 15, 2016 10:43
-
-
Save rafald/f23ab7430fee2175d1480a7b3526e27e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //http://melpon.org/wandbox/permlink/YtEl1NtqNHgULC9X | |
| #include <utility> | |
| template <char... chars> | |
| using CharSeq = std::integer_sequence<char, chars...>; | |
| template <typename T, T... chars> | |
| constexpr CharSeq<chars...> operator""_cts() { return { }; } | |
| //NOTE zero storage - only copiler data stractures encode the string, zero runtime overhead - data | |
| #include <iostream> | |
| #include <boost/core/demangle.hpp> | |
| template <class CharSeqType> | |
| struct string_taged_type | |
| { | |
| }; | |
| //TODO make possible | |
| // string_taged_type<string_tag> | |
| // string_taged_type<"FBI"_lift> | |
| // instead verbose | |
| // string_taged_type<decltype(string_tag)> | |
| ///template <std::integer_sequence<char, char... chars>> | |
| ///struct string_taged_type2 { }; | |
| #include <array> | |
| #include <experimental/array> | |
| template <typename T, T... chars> | |
| constexpr std::array<char,sizeof...(chars)> operator""_arr0() { return {chars...}; } | |
| // note there are runtime data involved | |
| template <typename T, T... chars> | |
| constexpr std::array<char,sizeof...(chars)> operator""_arr() { return std::experimental::make_array(chars...); } | |
| template <char... chars> | |
| constexpr std::array<char,sizeof...(chars)> name(std::integer_sequence<char, chars...>) | |
| { | |
| return {};//TODO convert integer_sequence<char,...> to array<char,...> | |
| } | |
| int | |
| main () | |
| { | |
| constexpr auto string_tag = "string_tag"_cts; | |
| std::cout << boost::core::demangle(typeid(decltype(string_tag)).name()) << "\n"; | |
| std::cout << boost::core::demangle(typeid(string_taged_type<decltype(string_tag)>).name()) << "\n"; | |
| std::cout << boost::core::demangle(typeid(string_taged_type<decltype("FBI"_cts)>).name()) << "\n"; | |
| constexpr auto my_arr0 = "cpptruths"_arr0; | |
| std::cout << boost::core::demangle(typeid(decltype(my_arr0)).name()) << "\n"; | |
| //std::cout << my_arr0 << "\n"; | |
| constexpr auto myarr = "cpptruths"_arr; | |
| std::cout << boost::core::demangle(typeid(decltype(myarr)).name()) << "\n"; | |
| std::cout << myarr.data() << "\n"; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment