From ebade8122f080a3152e4a020943be3a25664441f Mon Sep 17 00:00:00 2001 From: yumetodo Date: Thu, 31 May 2018 16:21:21 +0900 Subject: [PATCH 01/68] feat: impl string_view detect macro --- include/string_split.hpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/include/string_split.hpp b/include/string_split.hpp index 3c2c0d4..d7ebd0b 100644 --- a/include/string_split.hpp +++ b/include/string_split.hpp @@ -1,5 +1,5 @@ /*============================================================================= - Copyright (C) 2016 yumetodo + Copyright (C) 2016-2018 yumetodo Distributed under the Boost Software License, Version 1.0. (See http://www.boost.org/LICENSE_1_0.txt) @@ -11,6 +11,24 @@ #include #include #include +#if defined(_MSC_VER) +# if _MSC_VER >= 1910 && _MSVC_LANG >= 201703 +# define HAS_CXX17_STRING_VIEW 1 +# endif +#elif defined(__clang__) +# if __clang_major__ >= 4 && __cplusplus >= 201703 +# define HAS_CXX17_STRING_VIEW 1 +# endif +#elif defined(__GCC__) +# if (__GCC__ > 7 || (__GCC__ == 7 && __GNUC_MINOR__ >= 1)) && __cplusplus >= 201703 +# define HAS_CXX17_STRING_VIEW 1 +# endif +#endif + +#ifdef HAS_CXX17_STRING_VIEW +# include +#endif + //Windows.hなどからくる min max マクロがdefineされるのを防ぐ #ifndef NOMINMAX @@ -588,3 +606,5 @@ constexpr detail::get_front front() noexcept { return{}; } constexpr detail::get_back back() noexcept { return{}; } constexpr detail::split_at_first at_first() noexcept { return{}; } constexpr detail::split_at_last at_last() noexcept { return{}; } + +#undef HAS_CXX17_STRING_VIEW From 99d1a8a71801198e8ca63754dce235f7197d9967 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Thu, 31 May 2018 21:32:03 +0900 Subject: [PATCH 02/68] chore: update iutest to avoid C4267 --- iutest | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iutest b/iutest index 6e307aa..2a84994 160000 --- a/iutest +++ b/iutest @@ -1 +1 @@ -Subproject commit 6e307aa60b6f620933d4597febcef04d6a778177 +Subproject commit 2a84994d6980e91ca1c3df292a46a68f406f41ab From a59d15bdf73446338ccf67a8099dffeab7cc44c9 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Thu, 31 May 2018 22:01:56 +0900 Subject: [PATCH 03/68] fix: update vs project for c++17 with vs2017.7 --- benchmark/benchmark.vcxproj | 16 ++++++++-------- sample/sample.vcxproj | 16 ++++++++-------- test/test.vcxproj | 28 ++++++++++++++++++++-------- 3 files changed, 36 insertions(+), 24 deletions(-) diff --git a/benchmark/benchmark.vcxproj b/benchmark/benchmark.vcxproj index 62a8d1e..1f92056 100644 --- a/benchmark/benchmark.vcxproj +++ b/benchmark/benchmark.vcxproj @@ -44,40 +44,40 @@ Application true - v140 + v141 Unicode Application false - v140 + v141 true Unicode Application true - v140 + v141 Unicode Application false - v140 + v141 true Unicode - v140_clang_3_7 + v141_clang_3_7 - v140_Clang_3_7 + v141_Clang_3_7 - v140_clang_3_7 + v141_clang_3_7 - v140_Clang_3_7 + v141_Clang_3_7 diff --git a/sample/sample.vcxproj b/sample/sample.vcxproj index ee5e2ed..f62d719 100644 --- a/sample/sample.vcxproj +++ b/sample/sample.vcxproj @@ -45,40 +45,40 @@ Application true - v140 + v141 Unicode Application false - v140 + v141 true Unicode Application true - v140 + v141 Unicode Application false - v140 + v141 true Unicode - v140_clang_3_7 + v141_clang_3_7 - v140_Clang_3_7 + v141_Clang_3_7 - v140_clang_3_7 + v141_clang_3_7 - v140_Clang_3_7 + v141_Clang_3_7 diff --git a/test/test.vcxproj b/test/test.vcxproj index 0292574..e62cedd 100644 --- a/test/test.vcxproj +++ b/test/test.vcxproj @@ -44,40 +44,40 @@ Application true - v140 + v141 Unicode Application false - v140 + v141 true Unicode Application true - v140 + v141 Unicode Application false - v140 + v141 true Unicode - v140_clang_c2 + v141_clang_c2 - v140_clang_c2 + v141_clang_c2 - v140_clang_c2 + v141_clang_c2 - v140_clang_c2 + v141_clang_c2 @@ -143,6 +143,8 @@ true ../include Async + /bigobj %(AdditionalOptions) + stdcpp17 Console @@ -159,6 +161,8 @@ true ../include Async + /bigobj %(AdditionalOptions) + stdcpp17 Console @@ -177,6 +181,8 @@ true ../include Async + /bigobj %(AdditionalOptions) + stdcpp17 Console @@ -197,6 +203,8 @@ true ../include Async + /bigobj %(AdditionalOptions) + stdcpp17 Console @@ -210,6 +218,7 @@ Enabled ../include + @@ -217,12 +226,14 @@ Disabled ../include + Enabled ../include + @@ -230,6 +241,7 @@ Disabled ../include + From 6131277bc7300192afb017ec7fb90484c221424a Mon Sep 17 00:00:00 2001 From: yumetodo Date: Fri, 1 Jun 2018 02:19:45 +0900 Subject: [PATCH 04/68] fix(test): cut out constant namespace to constant.hpp --- test/constant.hpp | 54 +++++++++++++++++++++++++++++++++++++++ test/test.cpp | 53 ++------------------------------------ test/test.vcxproj | 5 +++- test/test.vcxproj.filters | 7 ++++- 4 files changed, 66 insertions(+), 53 deletions(-) create mode 100644 test/constant.hpp diff --git a/test/constant.hpp b/test/constant.hpp new file mode 100644 index 0000000..1dc5c92 --- /dev/null +++ b/test/constant.hpp @@ -0,0 +1,54 @@ +#ifndef STRING_SPLIT_TEST_CONSTANT_HPP_ +#define STRING_SPLIT_TEST_CONSTANT_HPP_ +#include +namespace constant { +#define STRING_SPLIT_TEST_CONSTANT_REGISTER_CHAR(identifier, no_prefix_char_literal) \ + template inline constexpr CharType identifier(); \ + template<> inline constexpr char identifier() { return no_prefix_char_literal; } \ + template<> inline constexpr wchar_t identifier() { return L ## no_prefix_char_literal; } \ + template<> inline constexpr char16_t identifier() { return u ## no_prefix_char_literal; } \ + template<> inline constexpr char32_t identifier() { return U ## no_prefix_char_literal; } +#define STRING_SPLIT_TEST_CONSTANT_REGISTER_STRING(identifier, no_prefix_string_literal) \ + template inline constexpr const CharType* identifier(); \ + template<> inline constexpr const char* identifier() { return no_prefix_string_literal; } \ + template<> inline constexpr const wchar_t* identifier() { return L ## no_prefix_string_literal; } \ + template<> inline constexpr const char16_t* identifier() { return u ## no_prefix_string_literal; } \ + template<> inline constexpr const char32_t* identifier() { return U ## no_prefix_string_literal; } +#define STRING_SPLIT_TEST_CONSTANT_REGISTER_USTRING(identifier, no_prefix_string_literal) \ + template inline constexpr const CharType* identifier(); \ + template<> inline constexpr const wchar_t* identifier() { return L ## no_prefix_string_literal; } \ + template<> inline constexpr const char16_t* identifier() { return u ## no_prefix_string_literal; } \ + template<> inline constexpr const char32_t* identifier() { return U ## no_prefix_string_literal; } + + STRING_SPLIT_TEST_CONSTANT_REGISTER_CHAR(space, ' '); + STRING_SPLIT_TEST_CONSTANT_REGISTER_CHAR(comma, ','); + STRING_SPLIT_TEST_CONSTANT_REGISTER_CHAR(colon, ':'); + STRING_SPLIT_TEST_CONSTANT_REGISTER_USTRING(wspace, " "); + STRING_SPLIT_TEST_CONSTANT_REGISTER_STRING(space_underscore, "_ "); + STRING_SPLIT_TEST_CONSTANT_REGISTER_STRING(space_comma, ", "); + STRING_SPLIT_TEST_CONSTANT_REGISTER_STRING(arikitari_na_world, "arikitari na world!"); + STRING_SPLIT_TEST_CONSTANT_REGISTER_STRING(arikitari_na_world_underscore, "arikitari na_world!"); + STRING_SPLIT_TEST_CONSTANT_REGISTER_STRING(arikitari_na, "arikitari na"); + STRING_SPLIT_TEST_CONSTANT_REGISTER_STRING(na_world, "na_world!"); + STRING_SPLIT_TEST_CONSTANT_REGISTER_STRING(arikitari, "arikitari"); + STRING_SPLIT_TEST_CONSTANT_REGISTER_STRING(na, "na"); + STRING_SPLIT_TEST_CONSTANT_REGISTER_STRING(world, "world!"); + STRING_SPLIT_TEST_CONSTANT_REGISTER_USTRING(arikitarina_sekai, "ありきたりな 世界"); + STRING_SPLIT_TEST_CONSTANT_REGISTER_USTRING(arikitarina_sekai_wspace, "ありきたりな 世界"); + STRING_SPLIT_TEST_CONSTANT_REGISTER_USTRING(arikitarina, "ありきたりな"); + STRING_SPLIT_TEST_CONSTANT_REGISTER_USTRING(sekai, "世界"); + STRING_SPLIT_TEST_CONSTANT_REGISTER_STRING(csv_data_123_421_113, "123,421,113"); + STRING_SPLIT_TEST_CONSTANT_REGISTER_STRING(csv_data_123_421_113_with_space, "123, 421, 113"); + STRING_SPLIT_TEST_CONSTANT_REGISTER_STRING(cpp_type_data1, "std::basic_istream >::ignore"); + STRING_SPLIT_TEST_CONSTANT_REGISTER_STRING(cpp_type_data2, "dxle::sound_c LoadSoundMem"); + STRING_SPLIT_TEST_CONSTANT_REGISTER_STRING(cpp_basic_istream, "std::basic_istream >"); + STRING_SPLIT_TEST_CONSTANT_REGISTER_STRING(cpp_basic_istream_part, "std::basic_istream #include #include -namespace constant { -#define STRING_SPLIT_TEST_CONSTANT_REGISTER_CHAR(identifier, no_prefix_char_literal) \ - template constexpr CharType identifier(); \ - template<> constexpr char identifier() { return no_prefix_char_literal; } \ - template<> constexpr wchar_t identifier() { return L ## no_prefix_char_literal; } \ - template<> constexpr char16_t identifier() { return u ## no_prefix_char_literal; } \ - template<> constexpr char32_t identifier() { return U ## no_prefix_char_literal; } -#define STRING_SPLIT_TEST_CONSTANT_REGISTER_STRING(identifier, no_prefix_string_literal) \ - template constexpr const CharType* identifier(); \ - template<> constexpr const char* identifier() { return no_prefix_string_literal; } \ - template<> constexpr const wchar_t* identifier() { return L ## no_prefix_string_literal; } \ - template<> constexpr const char16_t* identifier() { return u ## no_prefix_string_literal; } \ - template<> constexpr const char32_t* identifier() { return U ## no_prefix_string_literal; } -#define STRING_SPLIT_TEST_CONSTANT_REGISTER_USTRING(identifier, no_prefix_string_literal) \ - template constexpr const CharType* identifier(); \ - template<> constexpr const wchar_t* identifier() { return L ## no_prefix_string_literal; } \ - template<> constexpr const char16_t* identifier() { return u ## no_prefix_string_literal; } \ - template<> constexpr const char32_t* identifier() { return U ## no_prefix_string_literal; } - - STRING_SPLIT_TEST_CONSTANT_REGISTER_CHAR(space, ' '); - STRING_SPLIT_TEST_CONSTANT_REGISTER_CHAR(comma, ','); - STRING_SPLIT_TEST_CONSTANT_REGISTER_CHAR(colon, ':'); - STRING_SPLIT_TEST_CONSTANT_REGISTER_USTRING(wspace, " "); - STRING_SPLIT_TEST_CONSTANT_REGISTER_STRING(space_underscore, "_ "); - STRING_SPLIT_TEST_CONSTANT_REGISTER_STRING(space_comma, ", "); - STRING_SPLIT_TEST_CONSTANT_REGISTER_STRING(arikitari_na_world, "arikitari na world!"); - STRING_SPLIT_TEST_CONSTANT_REGISTER_STRING(arikitari_na_world_underscore, "arikitari na_world!"); - STRING_SPLIT_TEST_CONSTANT_REGISTER_STRING(arikitari_na, "arikitari na"); - STRING_SPLIT_TEST_CONSTANT_REGISTER_STRING(na_world, "na_world!"); - STRING_SPLIT_TEST_CONSTANT_REGISTER_STRING(arikitari, "arikitari"); - STRING_SPLIT_TEST_CONSTANT_REGISTER_STRING(na, "na"); - STRING_SPLIT_TEST_CONSTANT_REGISTER_STRING(world, "world!"); - STRING_SPLIT_TEST_CONSTANT_REGISTER_USTRING(arikitarina_sekai, "ありきたりな 世界"); - STRING_SPLIT_TEST_CONSTANT_REGISTER_USTRING(arikitarina_sekai_wspace, "ありきたりな 世界"); - STRING_SPLIT_TEST_CONSTANT_REGISTER_USTRING(arikitarina, "ありきたりな"); - STRING_SPLIT_TEST_CONSTANT_REGISTER_USTRING(sekai, "世界"); - STRING_SPLIT_TEST_CONSTANT_REGISTER_STRING(csv_data_123_421_113, "123,421,113"); - STRING_SPLIT_TEST_CONSTANT_REGISTER_STRING(csv_data_123_421_113_with_space, "123, 421, 113"); - STRING_SPLIT_TEST_CONSTANT_REGISTER_STRING(cpp_type_data1, "std::basic_istream >::ignore"); - STRING_SPLIT_TEST_CONSTANT_REGISTER_STRING(cpp_type_data2, "dxle::sound_c LoadSoundMem"); - STRING_SPLIT_TEST_CONSTANT_REGISTER_STRING(cpp_basic_istream, "std::basic_istream >"); - STRING_SPLIT_TEST_CONSTANT_REGISTER_STRING(cpp_basic_istream_part, "std::basic_istream struct StringSplitLvalue : public ::iutest::Test {}; IUTEST_TYPED_TEST_CASE(StringSplitLvalue, ::iutest::Types); diff --git a/test/test.vcxproj b/test/test.vcxproj index e62cedd..9a1af92 100644 --- a/test/test.vcxproj +++ b/test/test.vcxproj @@ -1,4 +1,4 @@ - + @@ -246,6 +246,9 @@ + + + diff --git a/test/test.vcxproj.filters b/test/test.vcxproj.filters index bb4a210..cd9329c 100644 --- a/test/test.vcxproj.filters +++ b/test/test.vcxproj.filters @@ -1,4 +1,4 @@ - + @@ -19,4 +19,9 @@ ソース ファイル + + + ヘッダー ファイル + + \ No newline at end of file From 1e5307deb7b1e51ee372bb89a677e5a97dce0a86 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Sat, 2 Jun 2018 01:05:52 +0900 Subject: [PATCH 05/68] fix: rename HAS_CXX17_STRING_VIEW macro to avoid conflict --- include/string_split.hpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/include/string_split.hpp b/include/string_split.hpp index d7ebd0b..9f4fc8e 100644 --- a/include/string_split.hpp +++ b/include/string_split.hpp @@ -1,4 +1,4 @@ -/*============================================================================= +/*============================================================================= Copyright (C) 2016-2018 yumetodo Distributed under the Boost Software License, Version 1.0. @@ -13,19 +13,19 @@ #include #if defined(_MSC_VER) # if _MSC_VER >= 1910 && _MSVC_LANG >= 201703 -# define HAS_CXX17_STRING_VIEW 1 +# define STRING_SPLIT_HAS_CXX17_STRING_VIEW 1 # endif #elif defined(__clang__) # if __clang_major__ >= 4 && __cplusplus >= 201703 -# define HAS_CXX17_STRING_VIEW 1 +# define STRING_SPLIT_HAS_CXX17_STRING_VIEW 1 # endif #elif defined(__GCC__) # if (__GCC__ > 7 || (__GCC__ == 7 && __GNUC_MINOR__ >= 1)) && __cplusplus >= 201703 -# define HAS_CXX17_STRING_VIEW 1 +# define STRING_SPLIT_HAS_CXX17_STRING_VIEW 1 # endif #endif -#ifdef HAS_CXX17_STRING_VIEW +#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW # include #endif @@ -607,4 +607,4 @@ constexpr detail::get_back back() noexcept { return{}; } constexpr detail::split_at_first at_first() noexcept { return{}; } constexpr detail::split_at_last at_last() noexcept { return{}; } -#undef HAS_CXX17_STRING_VIEW +#undef STRING_SPLIT_HAS_CXX17_STRING_VIEW From c19aa614463fbd6a85d7e31dd659f0d28be466e5 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Sat, 2 Jun 2018 01:08:59 +0900 Subject: [PATCH 06/68] fix: provie STRING_SPLIT_HAS_CXX17_STRING_VIEW macro --- include/string_split.hpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/include/string_split.hpp b/include/string_split.hpp index 9f4fc8e..c50fee4 100644 --- a/include/string_split.hpp +++ b/include/string_split.hpp @@ -606,5 +606,3 @@ constexpr detail::get_front front() noexcept { return{}; } constexpr detail::get_back back() noexcept { return{}; } constexpr detail::split_at_first at_first() noexcept { return{}; } constexpr detail::split_at_last at_last() noexcept { return{}; } - -#undef STRING_SPLIT_HAS_CXX17_STRING_VIEW From 2c0bc5f5ddfb1cb61793329acb3eed53da478e31 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Sat, 2 Jun 2018 01:18:13 +0900 Subject: [PATCH 07/68] feat: add string_view minimam support(no operation) --- include/string_split.hpp | 48 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/include/string_split.hpp b/include/string_split.hpp index c50fee4..05626d2 100644 --- a/include/string_split.hpp +++ b/include/string_split.hpp @@ -44,6 +44,9 @@ namespace detail { using std::vector; template using b_str = std::basic_string; +#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW + template using b_str_view = std::basic_string_view; +#endif using std::is_same; using std::size_t; template @@ -83,6 +86,18 @@ namespace detail { template struct is_stl_string : is_stl_string {}; template struct is_stl_string> : std::integral_constant>::value> {}; +#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW + // + // is_stl_string_view + // + template + struct is_stl_string_view : conditional_t::value, is_stl_string_view>, std::false_type> {}; + template struct is_stl_string_view : is_stl_string_view {}; + template struct is_stl_string_view : is_stl_string_view {}; + template struct is_stl_string_view : is_stl_string_view {}; + template + struct is_stl_string_view> : std::integral_constant>::value> {}; +#endif } struct subroutine_base {}; template struct is_subroutine : std::is_base_of {}; @@ -145,6 +160,13 @@ namespace detail { using char_type = typename StlString::value_type; b_str delim; size_t index; }; +#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW + template + struct split_helper_index { + using char_type = typename StlStringView::value_type; + b_str_view delim; size_t index; + }; +#endif template struct split_helper_conv_func; template @@ -168,6 +190,15 @@ namespace detail { static constexpr bool result_is_void = std::is_same::value; b_str delim; FuncType f; }; +#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW + template + struct split_helper_conv_func { + using char_type = typename StlStringView::value_type; + using result_type = std::invoke_result_t>; + static constexpr bool result_is_void = std::is_same::value; + b_str delim; FuncType f; + }; +#endif template struct split_helper; template @@ -203,6 +234,19 @@ namespace detail { template::value, std::nullptr_t> = nullptr> split_helper_subroutine operator>> (Subroutine) const noexcept { return{ std::move(delim) }; } }; +#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW + template + struct split_helper { + using char_type = typename StlStringView::value_type; + b_str_view delim; + split_helper_index operator[](size_t n) const noexcept { return{ std::move(delim), n }; } + template::value, std::nullptr_t> = nullptr> + split_helper_conv_func operator >> (FuncType&& f) const { return{ std::move(delim), std::forward(f) }; } + split_helper_index operator>>(get_front) const noexcept { return{ std::move(delim), 0 }; } + template::value, std::nullptr_t> = nullptr> + split_helper_subroutine operator>> (Subroutine) const noexcept { return{ std::move(delim) }; } + }; +#endif //back()の時 template b_str operator| (const b_str& str, const split_helper_subroutine& info) @@ -602,6 +646,10 @@ template split(CStr delim) noexcept { return{ delim }; } template::value, std::nullptr_t>::type = nullptr> detail::split_helper split(StlString delim) noexcept { return{ std::move(delim) }; } +#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW +template::value, std::nullptr_t>::type = nullptr> +detail::split_helper split(StlStringView delim) noexcept { return{ delim }; } +#endif constexpr detail::get_front front() noexcept { return{}; } constexpr detail::get_back back() noexcept { return{}; } constexpr detail::split_at_first at_first() noexcept { return{}; } From f8aa607d3ae3e1f7336e5c82f42b941040846e85 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Sat, 2 Jun 2018 01:23:32 +0900 Subject: [PATCH 08/68] feat(multi-delim, op[] | get_front()): add impl Try to support string_view(fail on vs). --- include/string_split.hpp | 24 +++++++++++++++++++++--- test/test.vcxproj | 1 + test/test.vcxproj.filters | 5 ++++- test/test_cxx17_string_view.cpp | 18 ++++++++++++++++++ 4 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 test/test_cxx17_string_view.cpp diff --git a/include/string_split.hpp b/include/string_split.hpp index 05626d2..1a0306c 100644 --- a/include/string_split.hpp +++ b/include/string_split.hpp @@ -286,7 +286,7 @@ namespace detail { if (b_str::npos == pos) return{ { {}, str } }; return { { str.substr(0, str.find_last_not_of(info.delim, pos) + 1), str.substr(pos + 1) } }; } - //区切り文字1文字, operator[]の時 + //区切り文字1文字, operator[] or get_front()の時 template b_str operator| (const b_str& str, const split_helper_index& info) { @@ -300,13 +300,31 @@ namespace detail { if(i < info.index) throw std::out_of_range("index(" + std::to_string(info.index) + ") is too big."); return str.substr(pre, pos - pre - 1); } - //区切り文字複数, operator[]の時 + //区切り文字複数, operator[] or get_front()の時 +#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW + template< + typename StrType, typename DelimType, bool is_c_str, bool is_stl_string, typename CharType = typename StrType::char_type, + enable_if_t, + type_traits::is_stl_string_view + >, + std::is_same::char_type> + >, std::nullptr_t> = nullptr + > + auto operator| (const StrType& str, const split_helper_index& info) -> StrType +#else template auto operator| (const b_str& str, const split_helper_index& info) -> enable_if_t< - (is_c_str || is_stl_string) && is_same::char_type>::value, + //is_c_str: true && is_stl_string: true => impossible!!! + //is_c_str: true && is_stl_string: false => const T* + //is_c_str: false && is_stl_string: true => std::basic_string + //is_c_str: false && is_stl_string: false => std::basic_string_view + !(is_c_str && is_stl_string) && is_same::char_type>::value, b_str > +#endif { size_t pre = 0, pos = 0, i; for (i = 0; i < info.index + 1; ++i) { diff --git a/test/test.vcxproj b/test/test.vcxproj index 9a1af92..9c5f202 100644 --- a/test/test.vcxproj +++ b/test/test.vcxproj @@ -245,6 +245,7 @@ + diff --git a/test/test.vcxproj.filters b/test/test.vcxproj.filters index cd9329c..ab4e1be 100644 --- a/test/test.vcxproj.filters +++ b/test/test.vcxproj.filters @@ -1,4 +1,4 @@ - + @@ -18,6 +18,9 @@ ソース ファイル + + ソース ファイル + diff --git a/test/test_cxx17_string_view.cpp b/test/test_cxx17_string_view.cpp new file mode 100644 index 0000000..c0a6420 --- /dev/null +++ b/test/test_cxx17_string_view.cpp @@ -0,0 +1,18 @@ +#include "../include/string_split.hpp" +#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW +#include "../iutest/include/iutest.hpp" +#include "constant.hpp" +#include +#include +#include +template +struct StringViewSplit : public ::iutest::Test {}; +IUTEST_TYPED_TEST_CASE(StringViewSplit, ::iutest::Types); +IUTEST_TYPED_TEST(StringViewSplit, chain_front_by_c_str) +{ + using char_type = TypeParam; + const std::basic_string_view s = constant::arikitari_na_world_underscore(); + constexpr auto delim = constant::space_underscore(); + IUTEST_ASSERT_EQ(constant::arikitari(), s | split(delim) >> front()); +} +#endif From 72470ed89827fa78985bab8ebd4688ec413bdd29 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Sat, 2 Jun 2018 16:38:58 +0900 Subject: [PATCH 09/68] fix(multi-delim, op[] | get_front()): fix typo s/char_type/value_type/ This change fix vs error. Thanks @kazatsuyu ref: - https://twitter.com/kazatsuyu/status/1002790357896007680 --- include/string_split.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/string_split.hpp b/include/string_split.hpp index 1a0306c..a6a63d6 100644 --- a/include/string_split.hpp +++ b/include/string_split.hpp @@ -303,7 +303,7 @@ namespace detail { //区切り文字複数, operator[] or get_front()の時 #ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW template< - typename StrType, typename DelimType, bool is_c_str, bool is_stl_string, typename CharType = typename StrType::char_type, + typename StrType, typename DelimType, bool is_c_str, bool is_stl_string, typename CharType = typename StrType::value_type, enable_if_t, From ad42b5dd73e9563baf180d567fdb1208acd171bb Mon Sep 17 00:00:00 2001 From: yumetodo Date: Sat, 2 Jun 2018 21:02:09 +0900 Subject: [PATCH 10/68] refactor(multi-delim, op[] | get_front()): reduce tmp arg --- include/string_split.hpp | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/include/string_split.hpp b/include/string_split.hpp index a6a63d6..17ee575 100644 --- a/include/string_split.hpp +++ b/include/string_split.hpp @@ -97,6 +97,22 @@ namespace detail { template struct is_stl_string_view : is_stl_string_view {}; template struct is_stl_string_view> : std::integral_constant>::value> {}; + template constexpr bool is_stl_string_view_v = is_stl_string_view::value; + // + // is_stl_string_or_stl_string_view + // + template struct is_stl_string_or_stl_string_view : std::disjunction< + type_traits::is_stl_string, + type_traits::is_stl_string_view + > {}; + // + // contract_str_type + // + template struct contract_str_type : std::conjunction< + type_traits::is_stl_string_or_stl_string_view, + std::is_same + > {}; + template constexpr bool contract_str_type_v = contract_str_type::value; #endif } struct subroutine_base {}; @@ -303,16 +319,14 @@ namespace detail { //区切り文字複数, operator[] or get_front()の時 #ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW template< - typename StrType, typename DelimType, bool is_c_str, bool is_stl_string, typename CharType = typename StrType::value_type, - enable_if_t, - type_traits::is_stl_string_view - >, - std::is_same::char_type> + typename StrType, typename DelimType, bool is_c_str, bool is_stl_string, + enable_if_t::char_type >, std::nullptr_t> = nullptr > auto operator| (const StrType& str, const split_helper_index& info) -> StrType + { #else template auto operator| (const b_str& str, const split_helper_index& info) @@ -324,13 +338,14 @@ namespace detail { !(is_c_str && is_stl_string) && is_same::char_type>::value, b_str > -#endif { + using StrType = b_str; +#endif size_t pre = 0, pos = 0, i; for (i = 0; i < info.index + 1; ++i) { if(pos) pre = pos = str.find_first_not_of(info.delim, pos); pos = str.find_first_of(info.delim, pos); - if (b_str::npos == pos) break; + if (StrType::npos == pos) break; } if (i < info.index) throw std::out_of_range("index(" + std::to_string(info.index) + ") is too big."); return str.substr(pre, pos - pre); From 4acaa4bf5f42fb0281b28c7516448404a0a664af Mon Sep 17 00:00:00 2001 From: yumetodo Date: Sat, 9 Jun 2018 14:09:43 +0900 Subject: [PATCH 11/68] feat(test/(multi-delim, op[] | front()): add test --- test/test.cpp | 50 ++++++++++++++++++++++++++++++ test/test_cxx17_string_view.cpp | 55 ++++++++++++++++++++++++++++++++- 2 files changed, 104 insertions(+), 1 deletion(-) diff --git a/test/test.cpp b/test/test.cpp index 2af132f..1f3bc20 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -34,6 +34,15 @@ IUTEST_TYPED_TEST(StringSplitLvalue, chain_front_by_stl_str) const std::basic_string delim = constant::space_underscore(); IUTEST_ASSERT_EQ(constant::arikitari(), s | split(delim) >> front()); } +#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW +IUTEST_TYPED_TEST(StringSplitLvalue, chain_front_by_stl_str_view) +{ + using char_type = TypeParam; + const std::basic_string s = constant::arikitari_na_world_underscore(); + const std::basic_string_view delim = constant::space_underscore(); + IUTEST_ASSERT_EQ(constant::arikitari(), s | split(delim) >> front()); +} +#endif IUTEST_TYPED_TEST(StringSplitLvalue, chain_back_by_singe_char) { using char_type = TypeParam; @@ -204,6 +213,21 @@ IUTEST_TYPED_TEST(StringSplitLvalue, ExtractByStlStr) IUTEST_EXPECT_THROW(s | split(delim)[3250], std::out_of_range); IUTEST_EXPECT_THROW(s | split(delim)[std::numeric_limits::max()], std::out_of_range); } +#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW +IUTEST_TYPED_TEST(StringSplitLvalue, ExtractByStlStrView) +{ + using char_type = TypeParam; + const std::basic_string s = constant::arikitari_na_world_underscore(); + const std::basic_string_view delim = constant::space_underscore(); + IUTEST_ASSERT_EQ(constant::arikitari(), s | split(delim)[0]); + IUTEST_ASSERT_EQ(constant::na(), s | split(delim)[1]); + IUTEST_ASSERT_EQ(constant::world(), s | split(delim)[2]); + IUTEST_EXPECT_THROW(s | split(delim)[3], std::out_of_range); + IUTEST_EXPECT_THROW(s | split(delim)[5], std::out_of_range); + IUTEST_EXPECT_THROW(s | split(delim)[3250], std::out_of_range); + IUTEST_EXPECT_THROW(s | split(delim)[std::numeric_limits::max()], std::out_of_range); +} +#endif namespace StringSplitLvalue_SplitBySingeChar { template::value, std::nullptr_t> = nullptr> void without_char() @@ -365,6 +389,16 @@ IUTEST_TYPED_TEST(StringSplitRvalue, chain_front_by_stl_str) const auto re = s(constant::arikitari_na_world_underscore()) | split(delim) >> front(); IUTEST_ASSERT_EQ(constant::arikitari(), re); } +#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW +IUTEST_TYPED_TEST(StringSplitRvalue, chain_front_by_stl_str_view) +{ + using char_type = TypeParam; + using s = std::basic_string; + const std::basic_string_view delim = constant::space_underscore(); + const auto re = s(constant::arikitari_na_world_underscore()) | split(delim) >> front(); + IUTEST_ASSERT_EQ(constant::arikitari(), re); +} +#endif IUTEST_TYPED_TEST(StringSplitRvalue, chain_back_by_singe_char) { using char_type = TypeParam; @@ -544,6 +578,22 @@ IUTEST_TYPED_TEST(StringSplitRvalue, ExtractByStlStr) IUTEST_EXPECT_THROW(s(constant::arikitari_na_world_underscore()) | split(delim)[3250], std::out_of_range); IUTEST_EXPECT_THROW(s(constant::arikitari_na_world_underscore()) | split(delim)[lim::max()], std::out_of_range); } +#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW +IUTEST_TYPED_TEST(StringSplitRvalue, ExtractByStlStrView) +{ + using char_type = TypeParam; + using s = std::basic_string; + using lim = std::numeric_limits; + const std::basic_string_view delim = constant::space_underscore(); + IUTEST_ASSERT_EQ(constant::arikitari(), s(constant::arikitari_na_world_underscore()) | split(delim)[0]); + IUTEST_ASSERT_EQ(constant::na(), s(constant::arikitari_na_world_underscore()) | split(delim)[1]); + IUTEST_ASSERT_EQ(constant::world(), s(constant::arikitari_na_world_underscore()) | split(delim)[2]); + IUTEST_EXPECT_THROW(s(constant::arikitari_na_world_underscore()) | split(delim)[3], std::out_of_range); + IUTEST_EXPECT_THROW(s(constant::arikitari_na_world_underscore()) | split(delim)[5], std::out_of_range); + IUTEST_EXPECT_THROW(s(constant::arikitari_na_world_underscore()) | split(delim)[3250], std::out_of_range); + IUTEST_EXPECT_THROW(s(constant::arikitari_na_world_underscore()) | split(delim)[lim::max()], std::out_of_range); +} +#endif namespace StringSplitRvalue_SplitBySingeChar { template::value, std::nullptr_t> = nullptr> void without_char() diff --git a/test/test_cxx17_string_view.cpp b/test/test_cxx17_string_view.cpp index c0a6420..692975d 100644 --- a/test/test_cxx17_string_view.cpp +++ b/test/test_cxx17_string_view.cpp @@ -1,4 +1,4 @@ -#include "../include/string_split.hpp" +#include "../include/string_split.hpp" #ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW #include "../iutest/include/iutest.hpp" #include "constant.hpp" @@ -15,4 +15,57 @@ IUTEST_TYPED_TEST(StringViewSplit, chain_front_by_c_str) constexpr auto delim = constant::space_underscore(); IUTEST_ASSERT_EQ(constant::arikitari(), s | split(delim) >> front()); } +IUTEST_TYPED_TEST(StringViewSplit, chain_front_by_stl_str) +{ + using char_type = TypeParam; + const std::basic_string_view s = constant::arikitari_na_world_underscore(); + const std::basic_string delim = constant::space_underscore(); + IUTEST_ASSERT_EQ(constant::arikitari(), s | split(delim) >> front()); +} +IUTEST_TYPED_TEST(StringViewSplit, chain_front_by_stl_str_view) +{ + using char_type = TypeParam; + const std::basic_string_view s = constant::arikitari_na_world_underscore(); + const std::basic_string_view delim = constant::space_underscore(); + IUTEST_ASSERT_EQ(constant::arikitari(), s | split(delim) >> front()); +} +IUTEST_TYPED_TEST(StringViewSplit, ExtractByCStr) +{ + using char_type = TypeParam; + const std::basic_string_view s = constant::arikitari_na_world_underscore(); + constexpr auto delim = constant::space_underscore(); + IUTEST_ASSERT_EQ(constant::arikitari(), s | split(delim)[0]); + IUTEST_ASSERT_EQ(constant::na(), s | split(delim)[1]); + IUTEST_ASSERT_EQ(constant::world(), s | split(delim)[2]); + IUTEST_EXPECT_THROW(s | split(delim)[3], std::out_of_range); + IUTEST_EXPECT_THROW(s | split(delim)[5], std::out_of_range); + IUTEST_EXPECT_THROW(s | split(delim)[3250], std::out_of_range); + IUTEST_EXPECT_THROW(s | split(delim)[std::numeric_limits::max()], std::out_of_range); +} +IUTEST_TYPED_TEST(StringViewSplit, ExtractByStlStr) +{ + using char_type = TypeParam; + const std::basic_string_view s = constant::arikitari_na_world_underscore(); + const std::basic_string delim = constant::space_underscore(); + IUTEST_ASSERT_EQ(constant::arikitari(), s | split(delim)[0]); + IUTEST_ASSERT_EQ(constant::na(), s | split(delim)[1]); + IUTEST_ASSERT_EQ(constant::world(), s | split(delim)[2]); + IUTEST_EXPECT_THROW(s | split(delim)[3], std::out_of_range); + IUTEST_EXPECT_THROW(s | split(delim)[5], std::out_of_range); + IUTEST_EXPECT_THROW(s | split(delim)[3250], std::out_of_range); + IUTEST_EXPECT_THROW(s | split(delim)[std::numeric_limits::max()], std::out_of_range); +} +IUTEST_TYPED_TEST(StringViewSplit, ExtractByStlStrView) +{ + using char_type = TypeParam; + const std::basic_string_view s = constant::arikitari_na_world_underscore(); + const std::basic_string_view delim = constant::space_underscore(); + IUTEST_ASSERT_EQ(constant::arikitari(), s | split(delim)[0]); + IUTEST_ASSERT_EQ(constant::na(), s | split(delim)[1]); + IUTEST_ASSERT_EQ(constant::world(), s | split(delim)[2]); + IUTEST_EXPECT_THROW(s | split(delim)[3], std::out_of_range); + IUTEST_EXPECT_THROW(s | split(delim)[5], std::out_of_range); + IUTEST_EXPECT_THROW(s | split(delim)[3250], std::out_of_range); + IUTEST_EXPECT_THROW(s | split(delim)[std::numeric_limits::max()], std::out_of_range); +} #endif From 1b77f6c66f320981e3a452d05a78a8653615bdf8 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Mon, 25 Jun 2018 21:59:09 +0900 Subject: [PATCH 12/68] feat(single-delim, op[] | front()): add impl --- include/string_split.hpp | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/include/string_split.hpp b/include/string_split.hpp index 17ee575..f6a93e9 100644 --- a/include/string_split.hpp +++ b/include/string_split.hpp @@ -166,6 +166,10 @@ namespace detail { using char_type = CharType; CharType delim; size_t index; }; + template + struct split_helper_get_front : split_helper_index { + constexpr split_helper_get_front(CharType d) : split_helper_index({d, 0}) {} + }; template struct split_helper_index { using char_type = remove_cv_t>; @@ -224,7 +228,7 @@ namespace detail { constexpr split_helper_index operator[](size_t n) const noexcept { return{ delim, n }; } template::value, std::nullptr_t> = nullptr> constexpr split_helper_conv_func operator>> (FuncType&& f) const { return{ delim, std::forward(f) }; } - constexpr split_helper_index operator>>(get_front) const noexcept { return{ delim, 0 }; } + constexpr split_helper_get_front operator>>(get_front) const noexcept { return{ delim }; } template::value, std::nullptr_t> = nullptr> constexpr split_helper_subroutine operator>> (Subroutine) const noexcept { return{ delim }; } }; @@ -302,21 +306,39 @@ namespace detail { if (b_str::npos == pos) return{ { {}, str } }; return { { str.substr(0, str.find_last_not_of(info.delim, pos) + 1), str.substr(pos + 1) } }; } - //区切り文字1文字, operator[] or get_front()の時 + //区切り文字1文字, operator[] or front()の時 +#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW + template< + typename StrType, typename CharType, + enable_if_t, std::nullptr_t> = nullptr + > + StrType operator| (const StrType& str, const split_helper_index& info) + { +#else template b_str operator| (const b_str& str, const split_helper_index& info) { + using StrType = b_str; +#endif size_t pre = 0, pos = 0, i; for (i = 0; i < info.index + 1; ++i) { pre = pos; pos = str.find_first_of(info.delim, pos); - if (b_str::npos == pos) break; + if (StrType::npos == pos) break; ++pos; } if(i < info.index) throw std::out_of_range("index(" + std::to_string(info.index) + ") is too big."); return str.substr(pre, pos - pre - 1); } - //区切り文字複数, operator[] or get_front()の時 +#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW + //区切り文字1文字, front()の時 + template + b_str_view operator| (const b_str_view& str, const split_helper_get_front& info) noexcept + { + return str.substr(0, str.find_first_of(info.delim)); + } +#endif + //区切り文字複数, operator[] or front()の時 #ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW template< typename StrType, typename DelimType, bool is_c_str, bool is_stl_string, From 60a9a2392c6729bf320dc4c67f64ee34e4b6bf75 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Mon, 25 Jun 2018 22:01:23 +0900 Subject: [PATCH 13/68] feat(test/single-delim, op[] | front()): add impl --- test/test_cxx17_string_view.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/test_cxx17_string_view.cpp b/test/test_cxx17_string_view.cpp index 692975d..8b22a60 100644 --- a/test/test_cxx17_string_view.cpp +++ b/test/test_cxx17_string_view.cpp @@ -8,6 +8,13 @@ template struct StringViewSplit : public ::iutest::Test {}; IUTEST_TYPED_TEST_CASE(StringViewSplit, ::iutest::Types); +IUTEST_TYPED_TEST(StringViewSplit, chain_front_by_singe_char) +{ + using char_type = TypeParam; + const std::basic_string_view s = constant::cpp_basic_istream(); + const auto re = s | split(constant::space()) >> front(); + IUTEST_ASSERT_EQ(std::basic_string_view(constant::cpp_basic_istream_part()), re); +} IUTEST_TYPED_TEST(StringViewSplit, chain_front_by_c_str) { using char_type = TypeParam; @@ -29,6 +36,19 @@ IUTEST_TYPED_TEST(StringViewSplit, chain_front_by_stl_str_view) const std::basic_string_view delim = constant::space_underscore(); IUTEST_ASSERT_EQ(constant::arikitari(), s | split(delim) >> front()); } +IUTEST_TYPED_TEST(StringViewSplit, ExtractBySingeChar) +{ + using char_type = TypeParam; + constexpr char_type space = constant::space(); + const std::basic_string s = constant::arikitari_na_world(); + IUTEST_ASSERT_EQ(constant::arikitari(), s | split(space)[0]); + IUTEST_ASSERT_EQ(constant::na(), s | split(space)[1]); + IUTEST_ASSERT_EQ(constant::world(), s | split(space)[2]); + IUTEST_EXPECT_THROW(s | split(space)[3], std::out_of_range); + IUTEST_EXPECT_THROW(s | split(space)[5], std::out_of_range); + IUTEST_EXPECT_THROW(s | split(space)[3250], std::out_of_range); + IUTEST_EXPECT_THROW(s | split(space)[std::numeric_limits::max()], std::out_of_range); +} IUTEST_TYPED_TEST(StringViewSplit, ExtractByCStr) { using char_type = TypeParam; From dac1f0ddb42ead5574300a6aa497dd5d3b7062bc Mon Sep 17 00:00:00 2001 From: yumetodo Date: Mon, 25 Jun 2018 22:04:58 +0900 Subject: [PATCH 14/68] feat(back()): add impl --- include/string_split.hpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/include/string_split.hpp b/include/string_split.hpp index f6a93e9..89e9d90 100644 --- a/include/string_split.hpp +++ b/include/string_split.hpp @@ -1,4 +1,4 @@ -/*============================================================================= +/*============================================================================= Copyright (C) 2016-2018 yumetodo Distributed under the Boost Software License, Version 1.0. @@ -268,11 +268,21 @@ namespace detail { }; #endif //back()の時 +#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW + template< + typename StrType, typename DelimType, typename CharType, + enable_if_t, std::nullptr_t> = nullptr + > + StrType operator| (const StrType& str, const split_helper_subroutine& info) noexcept(type_traits::is_stl_string_view_v) + { +#else template b_str operator| (const b_str& str, const split_helper_subroutine& info) { + using StrType = b_str; +#endif const auto pos = str.find_first_of(info.delim); - return (b_str::npos == pos) ? str : str.substr(str.find_last_of(info.delim) + 1); + return (StrType::npos == pos) ? str : str.substr(str.find_last_of(info.delim) + 1); } //at_first().back()の時 template From 18584b8d0294ca3326ef65efe25b3b209b0c3a27 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Mon, 25 Jun 2018 22:05:15 +0900 Subject: [PATCH 15/68] feat(test/back()): add impl --- test/test.cpp | 19 +++++++++++++++++++ test/test_cxx17_string_view.cpp | 30 +++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/test/test.cpp b/test/test.cpp index 1f3bc20..751f5b0 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -64,6 +64,15 @@ IUTEST_TYPED_TEST(StringSplitLvalue, chain_back_by_stl_str) const std::basic_string delim = constant::space_underscore(); IUTEST_ASSERT_EQ(constant::world(), s | split(delim) >> back()); } +#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW +IUTEST_TYPED_TEST(StringSplitLvalue, chain_back_by_stl_str_view) +{ + using char_type = TypeParam; + const std::basic_string s = constant::arikitari_na_world_underscore(); + const std::basic_string_view delim = constant::space_underscore(); + IUTEST_ASSERT_EQ(constant::world(), s | split(delim) >> back()); +} +#endif IUTEST_TYPED_TEST(StringSplitLvalue, chain_at_first_front) { using char_type = TypeParam; @@ -422,6 +431,16 @@ IUTEST_TYPED_TEST(StringSplitRvalue, chain_back_by_stl_str) const auto re = s(constant::arikitari_na_world_underscore()) | split(delim) >> back(); IUTEST_ASSERT_EQ(constant::world(), re); } +#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW +IUTEST_TYPED_TEST(StringSplitRvalue, chain_back_by_stl_str_view) +{ + using char_type = TypeParam; + using s = std::basic_string; + const std::basic_string_view delim = constant::space_underscore(); + const auto re = s(constant::arikitari_na_world_underscore()) | split(delim) >> back(); + IUTEST_ASSERT_EQ(constant::world(), re); +} +#endif IUTEST_TYPED_TEST(StringSplitRvalue, chain_at_first_front) { using char_type = TypeParam; diff --git a/test/test_cxx17_string_view.cpp b/test/test_cxx17_string_view.cpp index 8b22a60..a3a4240 100644 --- a/test/test_cxx17_string_view.cpp +++ b/test/test_cxx17_string_view.cpp @@ -1,4 +1,4 @@ -#include "../include/string_split.hpp" +#include "../include/string_split.hpp" #ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW #include "../iutest/include/iutest.hpp" #include "constant.hpp" @@ -36,6 +36,34 @@ IUTEST_TYPED_TEST(StringViewSplit, chain_front_by_stl_str_view) const std::basic_string_view delim = constant::space_underscore(); IUTEST_ASSERT_EQ(constant::arikitari(), s | split(delim) >> front()); } +IUTEST_TYPED_TEST(StringViewSplit, chain_back_by_singe_char) +{ + using char_type = TypeParam; + const std::basic_string_view s = constant::arikitari_na_world(); + const auto re = s | split(constant::space()) >> back(); + IUTEST_ASSERT_EQ(constant::world(), re); +} +IUTEST_TYPED_TEST(StringViewSplit, chain_back_by_c_str) +{ + using char_type = TypeParam; + const std::basic_string_view s = constant::arikitari_na_world_underscore(); + constexpr auto delim = constant::space_underscore(); + IUTEST_ASSERT_EQ(constant::world(), s | split(delim) >> back()); +} +IUTEST_TYPED_TEST(StringViewSplit, chain_back_by_stl_str) +{ + using char_type = TypeParam; + const std::basic_string_view s = constant::arikitari_na_world_underscore(); + const std::basic_string delim = constant::space_underscore(); + IUTEST_ASSERT_EQ(constant::world(), s | split(delim) >> back()); +} +IUTEST_TYPED_TEST(StringViewSplit, chain_back_by_stl_str_view) +{ + using char_type = TypeParam; + const std::basic_string_view s = constant::arikitari_na_world_underscore(); + const std::basic_string_view delim = constant::space_underscore(); + IUTEST_ASSERT_EQ(constant::world(), s | split(delim) >> back()); +} IUTEST_TYPED_TEST(StringViewSplit, ExtractBySingeChar) { using char_type = TypeParam; From 5dd5496840013a78c4caf1773e228a03912ce293 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Mon, 25 Jun 2018 22:31:07 +0900 Subject: [PATCH 16/68] fix(constant): stop include cuchar --- test/constant.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/test/constant.hpp b/test/constant.hpp index 1dc5c92..debccf9 100644 --- a/test/constant.hpp +++ b/test/constant.hpp @@ -1,6 +1,5 @@ #ifndef STRING_SPLIT_TEST_CONSTANT_HPP_ #define STRING_SPLIT_TEST_CONSTANT_HPP_ -#include namespace constant { #define STRING_SPLIT_TEST_CONSTANT_REGISTER_CHAR(identifier, no_prefix_char_literal) \ template inline constexpr CharType identifier(); \ From 26609a177e43c50fa4a95a2bdd74793bd4177c10 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Thu, 28 Jun 2018 14:11:33 +0900 Subject: [PATCH 17/68] chore: update iutest note: try `git rm --cached -r . && git reset --hard` when you get CRLF warning. (ref: https://github.com/srz-zumix/iutest/issues/57) --- iutest | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iutest b/iutest index 2a84994..37deb72 160000 --- a/iutest +++ b/iutest @@ -1 +1 @@ -Subproject commit 2a84994d6980e91ca1c3df292a46a68f406f41ab +Subproject commit 37deb7293cd0193c7182e343174906063b0fda7f From 013ba09172186c949dd544c972f9aaab72e7b91b Mon Sep 17 00:00:00 2001 From: yumetodo Date: Sat, 7 Jul 2018 20:55:08 +0900 Subject: [PATCH 18/68] fix: s/__GCC__/__GNUC__/ when detect string_view --- include/string_split.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/string_split.hpp b/include/string_split.hpp index 89e9d90..d336441 100644 --- a/include/string_split.hpp +++ b/include/string_split.hpp @@ -19,8 +19,8 @@ # if __clang_major__ >= 4 && __cplusplus >= 201703 # define STRING_SPLIT_HAS_CXX17_STRING_VIEW 1 # endif -#elif defined(__GCC__) -# if (__GCC__ > 7 || (__GCC__ == 7 && __GNUC_MINOR__ >= 1)) && __cplusplus >= 201703 +#elif defined(__GNUC__) +# if (__GNUC__ > 7 || (__GNUC__ == 7 && __GNUC_MINOR__ >= 1)) && __cplusplus >= 201703 # define STRING_SPLIT_HAS_CXX17_STRING_VIEW 1 # endif #endif From a12447ebc48faa4e6eb496b0986edcf28e721a50 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Sat, 7 Jul 2018 20:56:38 +0900 Subject: [PATCH 19/68] chore: disable GCC's extra semi colon warning --- test/constant.hpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/constant.hpp b/test/constant.hpp index debccf9..e7e2d26 100644 --- a/test/constant.hpp +++ b/test/constant.hpp @@ -19,6 +19,10 @@ namespace constant { template<> inline constexpr const char16_t* identifier() { return u ## no_prefix_string_literal; } \ template<> inline constexpr const char32_t* identifier() { return U ## no_prefix_string_literal; } +#ifdef __GNUC__ +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wpedantic" +#endif STRING_SPLIT_TEST_CONSTANT_REGISTER_CHAR(space, ' '); STRING_SPLIT_TEST_CONSTANT_REGISTER_CHAR(comma, ','); STRING_SPLIT_TEST_CONSTANT_REGISTER_CHAR(colon, ':'); @@ -45,6 +49,9 @@ namespace constant { STRING_SPLIT_TEST_CONSTANT_REGISTER_STRING(cpp_dxle_sound_c, "dxle::sound_c"); STRING_SPLIT_TEST_CONSTANT_REGISTER_STRING(cpp_LoadSoundMem, "LoadSoundMem"); STRING_SPLIT_TEST_CONSTANT_REGISTER_STRING(ignore, "ignore"); +#ifdef __GNUC__ +# pragma GCC diagnostic pop +#endif #undef STRING_SPLIT_TEST_CONSTANT_REGISTER_CHAR #undef STRING_SPLIT_TEST_CONSTANT_REGISTER_STRING From cf660a61b00f1ec1725752173fb1f51305dab0c0 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Sat, 7 Jul 2018 20:57:13 +0900 Subject: [PATCH 20/68] feat(sample): add string_view sample --- sample/sample.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/sample/sample.cpp b/sample/sample.cpp index ac4bc18..f7214cc 100644 --- a/sample/sample.cpp +++ b/sample/sample.cpp @@ -13,14 +13,25 @@ int main() const auto s_1 = s | split(' ')[1]; if ("na" != s_1) return 1; std::string s2 = "123,421,113"; + + //lamda or class contain operator() const auto n1 = s2 | split(',') >> [](const std::string& s) { return std::stoi(s); - };//lamda or class contain operator() - //const auto n2 = s2 | split(',') >> std::stoi;//std::stoi's prototype is int(const std::string&, std::size_t*, int), not int(const std::string&). - const auto n2 = s2 | split(',') >> to_int;//function-pointer + }; + + //std::stoi's prototype is int(const std::string&, std::size_t*, int), not int(const std::string&). + //const auto n2 = s2 | split(',') >> std::stoi; + + //function-pointer + const auto n2 = s2 | split(',') >> to_int; if (n1 != n2) return 2; s2 | split(',') >> [](std::string&& s) { std::cout << s << std::endl; }; + +#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW + std::string_view sw = "arikitari na sekai"; + const auto r = sw | split(' ') >> back(); +#endif return 0; } \ No newline at end of file From b8817d69add822f5a5b80b9f4cfc270740f3d78e Mon Sep 17 00:00:00 2001 From: yumetodo Date: Sat, 7 Jul 2018 20:57:58 +0900 Subject: [PATCH 21/68] chore: update .gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 35d7bee..3e976bd 100644 --- a/.gitignore +++ b/.gitignore @@ -17,7 +17,7 @@ [Rr]eleases/ [Xx]64/ [Xx]86/ -[Bb]uild/ +[Bb]uild*/ bld/ [Bb]in/ [Oo]bj/ From 8fbe6efcc4446895a2721a9dac6c41fd58d1dcc0 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Sat, 7 Jul 2018 20:58:55 +0900 Subject: [PATCH 22/68] feat(CodeCoverage): import and devide genhtml step from https://github.com/bilke/cmake-modules/blob/master/CodeCoverage.cmake add SETUP_TARGET_FOR_COVERAGE_TO_HTML function to devide genhtml step because genhtml is not required on ci. remove SETUP_TARGET_FOR_COVERAGE_COBERTURA function because I don't use gcov directory. --- cmake/modules/CodeCoverage.cmake | 212 +++++++++++++++++++++++++++++++ 1 file changed, 212 insertions(+) create mode 100644 cmake/modules/CodeCoverage.cmake diff --git a/cmake/modules/CodeCoverage.cmake b/cmake/modules/CodeCoverage.cmake new file mode 100644 index 0000000..d88a728 --- /dev/null +++ b/cmake/modules/CodeCoverage.cmake @@ -0,0 +1,212 @@ +# Copyright (c) 2012 - 2017, Lars Bilke +# Copyright (c) 2018 yumetodo +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors +# may be used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# CHANGES: +# +# 2012-01-31, Lars Bilke +# - Enable Code Coverage +# +# 2013-09-17, Joakim Söderberg +# - Added support for Clang. +# - Some additional usage instructions. +# +# 2016-02-03, Lars Bilke +# - Refactored functions to use named parameters +# +# 2017-06-02, Lars Bilke +# - Merged with modified version from github.com/ufz/ogs +# +# +# USAGE: +# +# 1. Copy this file into your cmake modules path. +# +# 2. Add the following line to your CMakeLists.txt: +# include(CodeCoverage) +# +# 3. Append necessary compiler flags: +# APPEND_COVERAGE_COMPILER_FLAGS() +# +# 4. If you need to exclude additional directories from the report, specify them +# using the COVERAGE_EXCLUDES variable before calling SETUP_TARGET_FOR_COVERAGE. +# Example: +# set(COVERAGE_EXCLUDES 'dir1/*' 'dir2/*') +# +# 5. Use the functions described below to create a custom make target which +# runs your test executable and produces a code coverage report. +# +# 6. Build a Debug build: +# cmake -DCMAKE_BUILD_TYPE=Debug .. +# make +# make my_coverage_target +# + +include(CMakeParseArguments) + +# Check prereqs +find_program( GCOV_PATH gcov ) +find_program( LCOV_PATH NAMES lcov lcov.bat lcov.exe lcov.perl) +find_program( GENHTML_PATH NAMES genhtml genhtml.perl genhtml.bat ) +find_program( GCOVR_PATH gcovr PATHS ${CMAKE_SOURCE_DIR}/scripts/test) +find_program( SIMPLE_PYTHON_EXECUTABLE python ) + +if(NOT GCOV_PATH) + message(FATAL_ERROR "gcov not found! Aborting...") +endif() # NOT GCOV_PATH + +if("${CMAKE_CXX_COMPILER_ID}" MATCHES "(Apple)?[Cc]lang") + if("${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS 3) + message(FATAL_ERROR "Clang version must be 3.0.0 or greater! Aborting...") + endif() +elseif(NOT CMAKE_COMPILER_IS_GNUCXX) + message(FATAL_ERROR "Compiler is not GNU gcc! Aborting...") +endif() + +set(COVERAGE_COMPILER_FLAGS "-g -O0 --coverage -fprofile-arcs -ftest-coverage" + CACHE INTERNAL "") + +set(CMAKE_CXX_FLAGS_COVERAGE + ${COVERAGE_COMPILER_FLAGS} + CACHE STRING "Flags used by the C++ compiler during coverage builds." + FORCE ) +set(CMAKE_C_FLAGS_COVERAGE + ${COVERAGE_COMPILER_FLAGS} + CACHE STRING "Flags used by the C compiler during coverage builds." + FORCE ) +set(CMAKE_EXE_LINKER_FLAGS_COVERAGE + "" + CACHE STRING "Flags used for linking binaries during coverage builds." + FORCE ) +set(CMAKE_SHARED_LINKER_FLAGS_COVERAGE + "" + CACHE STRING "Flags used by the shared libraries linker during coverage builds." + FORCE ) +mark_as_advanced( + CMAKE_CXX_FLAGS_COVERAGE + CMAKE_C_FLAGS_COVERAGE + CMAKE_EXE_LINKER_FLAGS_COVERAGE + CMAKE_SHARED_LINKER_FLAGS_COVERAGE ) + +if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug") + message(WARNING "Code coverage results with an optimised (non-Debug) build may be misleading") +endif() # NOT CMAKE_BUILD_TYPE STREQUAL "Debug" + +if(CMAKE_C_COMPILER_ID STREQUAL "GNU") + link_libraries(gcov) +else() + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage") +endif() + +# Defines a target for running and collection code coverage information +# Builds dependencies, runs the given executable and outputs reports. +# NOTE! The executable should always have a ZERO as exit code otherwise +# the coverage generation will not complete. +# +# SETUP_TARGET_FOR_COVERAGE( +# NAME testrunner_coverage # New target name +# EXECUTABLE testrunner -j ${PROCESSOR_COUNT} # Executable in PROJECT_BINARY_DIR +# DEPENDENCIES testrunner # Dependencies to build first +# ) +function(SETUP_TARGET_FOR_COVERAGE) + + set(options NONE) + set(oneValueArgs NAME) + set(multiValueArgs EXECUTABLE EXECUTABLE_ARGS DEPENDENCIES) + cmake_parse_arguments(Coverage "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + if(NOT LCOV_PATH) + message(FATAL_ERROR "lcov not found! Aborting...") + endif() # NOT LCOV_PATH + + # Setup target + add_custom_target(${Coverage_NAME} + + # Cleanup lcov + COMMAND ${LCOV_PATH} --directory . --zerocounters + # Create baseline to make sure untouched files show up in the report + COMMAND ${LCOV_PATH} -c -i -d . -o ${Coverage_NAME}.base + + # Run tests + COMMAND ${Coverage_EXECUTABLE} + + # Capturing lcov counters and generating report + COMMAND ${LCOV_PATH} --directory . --capture --output-file ${Coverage_NAME}.info + # add baseline counters + COMMAND ${LCOV_PATH} -a ${Coverage_NAME}.base -a ${Coverage_NAME}.info --output-file ${Coverage_NAME}.total + COMMAND ${LCOV_PATH} --remove ${Coverage_NAME}.total ${COVERAGE_EXCLUDES} --output-file ${PROJECT_BINARY_DIR}/${Coverage_NAME}.info.cleaned + # COMMAND ${GENHTML_PATH} -o ${Coverage_NAME} ${PROJECT_BINARY_DIR}/${Coverage_NAME}.info.cleaned + COMMAND ${CMAKE_COMMAND} -E remove ${Coverage_NAME}.base ${Coverage_NAME}.total # ${PROJECT_BINARY_DIR}/${Coverage_NAME}.info.cleaned + + WORKING_DIRECTORY ${PROJECT_BINARY_DIR} + DEPENDS ${Coverage_DEPENDENCIES} + COMMENT "Resetting code coverage counters to zero.\nProcessing code coverage counters and generating report." + ) + + # Show where to find the lcov info report + add_custom_command(TARGET ${Coverage_NAME} POST_BUILD + COMMAND ; + COMMENT "Lcov code coverage info report saved in ${Coverage_NAME}.info." + ) +endfunction() # SETUP_TARGET_FOR_COVERAGE + +# Generate HTML from coverage info file +# +# SETUP_TARGET_FOR_COVERAGE_TO_HTML( +# NAME testrunner_coverage_to_html # New target name +# INFO_FILE_NAME testrunner_coverage # coverage task result file name +# DEPENDENCIES testrunner_coverage # Dependencies(coverage task, etc...) +# ) +function(SETUP_TARGET_FOR_COVERAGE_TO_HTML) + set(options NONE) + set(oneValueArgs NAME INFO_FILE_NAME) + set(multiValueArgs DEPENDENCIES) + cmake_parse_arguments(CoverageToHTML "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + if(NOT GENHTML_PATH) + message(FATAL_ERROR "genhtml not found! Aborting...") + endif() # NOT GENHTML_PATH + # Setup target + add_custom_target(${CoverageToHTML_NAME} + COMMAND ${GENHTML_PATH} -o ${CoverageToHTML_NAME} ${PROJECT_BINARY_DIR}/${CoverageToHTML_INFO_FILE_NAME} + WORKING_DIRECTORY ${PROJECT_BINARY_DIR} + DEPENDS ${CoverageToHTML_DEPENDENCIES} + COMMENT "Resetting code coverage counters to zero.\nProcessing code coverage counters and generating report." + ) + # Show info where to find the report + add_custom_command(TARGET ${CoverageToHTML_NAME} POST_BUILD + COMMAND ; + COMMENT "Open ./${CoverageToHTML_NAME}/index.html in your browser to view the coverage report." + ) +endfunction() + +function(APPEND_COVERAGE_COMPILER_FLAGS) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COVERAGE_COMPILER_FLAGS}" PARENT_SCOPE) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COVERAGE_COMPILER_FLAGS}" PARENT_SCOPE) + message(STATUS "Appending code coverage compiler flags: ${COVERAGE_COMPILER_FLAGS}") +endfunction() # APPEND_COVERAGE_COMPILER_FLAGS From 825d5844f4ed256529aed828d8003e180c8a62a6 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Sat, 7 Jul 2018 21:04:38 +0900 Subject: [PATCH 23/68] feat(DecideCXXStanderd): to use c++17 when supported --- cmake/modules/DecideCXXStanderd.cmake | 29 +++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 cmake/modules/DecideCXXStanderd.cmake diff --git a/cmake/modules/DecideCXXStanderd.cmake b/cmake/modules/DecideCXXStanderd.cmake new file mode 100644 index 0000000..8bfc528 --- /dev/null +++ b/cmake/modules/DecideCXXStanderd.cmake @@ -0,0 +1,29 @@ +function(DECIDE_CXX_STANDERD) + if(MSVC) + if(MSVC_VERSION GREATER_EQUAL 1910) + set(STRING_SPLIT_DEFAULT_CXX_STANDARD 17) + else() + set(STRING_SPLIT_DEFAULT_CXX_STANDARD 14) + endif() + elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 4.0) + set(STRING_SPLIT_DEFAULT_CXX_STANDARD 17) + else() + set(STRING_SPLIT_DEFAULT_CXX_STANDARD 14) + endif() + elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 7.1) + set(STRING_SPLIT_DEFAULT_CXX_STANDARD 17) + else() + set(STRING_SPLIT_DEFAULT_CXX_STANDARD 14) + endif() + else() + set(STRING_SPLIT_DEFAULT_CXX_STANDARD 14) + endif() + message("default CMAKE_CXX_STANDARD:${STRING_SPLIT_DEFAULT_CXX_STANDARD}") + set(CMAKE_CXX_STANDARD "${STRING_SPLIT_DEFAULT_CXX_STANDARD}" CACHE STRING "C++ version") + message("CMAKE_CXX_STANDARD:${CMAKE_CXX_STANDARD}") + if(CMAKE_CXX_STANDARD LESS 14) + message(FATAL_ERROR "Specify C++14 or later") + endif() +endfunction() \ No newline at end of file From 24eb6b6d825d7290e59b9d7809c7d29fc171349d Mon Sep 17 00:00:00 2001 From: yumetodo Date: Sat, 7 Jul 2018 21:07:37 +0900 Subject: [PATCH 24/68] feat: Hello cmake! --- .travis.yml | 11 ++++- CMakeLists.txt | 14 ++++++ benchmark/CMakeLists.txt | 30 +++++++++++++ sample/CMakeLists.txt | 40 +++++++++++++++++ test/CMakeLists.txt | 95 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 188 insertions(+), 2 deletions(-) create mode 100644 CMakeLists.txt create mode 100644 benchmark/CMakeLists.txt create mode 100644 sample/CMakeLists.txt create mode 100644 test/CMakeLists.txt diff --git a/.travis.yml b/.travis.yml index 0e13af6..74a8810 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,7 +34,14 @@ install: fi language: cpp script: - - make Release USE_COVERAGE=0 && ./test/test.out && ./sample/sample.out && make clean && make Debug && ./test/test.out && ./sample/sample.out + - mkdir build_release + - mkdir build_debug + - cd build_release + - cmake -DCMAKE_BUILD_TYPE=Release .. + - make ci + - cd ../build_debug + - cmake -DSTRING_SPLIT_ENABLE_COVERAGE="${USE_COVERALLS}" -DCMAKE_BUILD_TYPE=Debug .. + - make ci after_success: # Coverage - - if [ "${USE_COVERALLS}" = '1' ]; then cd ./test; make send-coveralls; fi + - if [ "${USE_COVERALLS}" = '1' ]; then lcoveralls --retry-count 3 ./build_debug/test/coverage.info.cleaned ; fi diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..d80a711 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.7) +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake/modules) +add_subdirectory(sample) +add_subdirectory(benchmark) +add_subdirectory(test) + +add_custom_target(ci + DEPENDS benchmark run_sample +) +if((CMAKE_BUILD_TYPE STREQUAL "Debug") AND ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") AND STRING_SPLIT_ENABLE_COVERAGE) + add_dependencies(ci test_coverage) +else() + add_dependencies(ci run_test) +endif() diff --git a/benchmark/CMakeLists.txt b/benchmark/CMakeLists.txt new file mode 100644 index 0000000..868f563 --- /dev/null +++ b/benchmark/CMakeLists.txt @@ -0,0 +1,30 @@ +cmake_minimum_required(VERSION 3.7) +enable_language(CXX) +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/../cmake/modules) + +# +# C++ version +# +include(DecideCXXStanderd) +DECIDE_CXX_STANDERD() +message("CMAKE_CXX_STANDARD:${CMAKE_CXX_STANDARD}") + +set(CMAKE_CXX_STANDARD_REQUIRED ON) #...is required... +set(CMAKE_CXX_EXTENSIONS OFF) #...without compiler extensions like gnu++11 + +# +# Set our project name +# +project(benchmark) + +# +# Source files +# +set(benchmark_src + "./benchmark.cpp" +) + +# +# Compile +# +add_executable(benchmark ${benchmark_src}) diff --git a/sample/CMakeLists.txt b/sample/CMakeLists.txt new file mode 100644 index 0000000..5472f5c --- /dev/null +++ b/sample/CMakeLists.txt @@ -0,0 +1,40 @@ +cmake_minimum_required(VERSION 3.7) +enable_language(CXX) +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/../cmake/modules) + +# +# C++ version +# +include(DecideCXXStanderd) +DECIDE_CXX_STANDERD() +message("CMAKE_CXX_STANDARD:${CMAKE_CXX_STANDARD}") + +set(CMAKE_CXX_STANDARD_REQUIRED ON) #...is required... +set(CMAKE_CXX_EXTENSIONS OFF) #...without compiler extensions like gnu++11 + +# +# Set our project name +# +project(sample) + +# +# Source files +# +set(sample_src + "./sample.cpp" +) + +# +# Compile +# +add_executable(sample ${sample_src}) + +# +# add Run task +# +add_custom_target(run_sample + COMMAND sample + WORKING_DIRECTORY ${PROJECT_BINARY_DIR} + DEPENDS sample + COMMENT "Execute produced executable." +) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..3d74fdd --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,95 @@ +cmake_minimum_required(VERSION 3.7) +enable_language(CXX) +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/../cmake/modules) + +# +# C++ version +# +include(DecideCXXStanderd) +DECIDE_CXX_STANDERD() +message("CMAKE_CXX_STANDARD:${CMAKE_CXX_STANDARD}") + +set(CMAKE_CXX_STANDARD_REQUIRED ON) #...is required... +set(CMAKE_CXX_EXTENSIONS OFF) #...without compiler extensions like gnu++11 + +# +# Config options +# +if((CMAKE_BUILD_TYPE STREQUAL "Debug") AND ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")) + message("you can specify STRING_SPLIT_ENABLE_COVERAGE") + option(STRING_SPLIT_ENABLE_COVERAGE "enable coverage" FALSE) +else() + set(STRING_SPLIT_ENABLE_COVERAGE FALSE) +endif() + +# +# Set our project name +# +project(test) + +# +# Source files +# +set(test_src + "./test.cpp" +) +if(CMAKE_CXX_STANDARD GREATER_EQUAL 17) + message("C++17 sources enabled") + list(APPEND test_src "./test_cxx17_string_view.cpp") +endif() + +if(STRING_SPLIT_ENABLE_COVERAGE) + message("coverage enabled") + include(CodeCoverage) + APPEND_COVERAGE_COMPILER_FLAGS() + set(COVERAGE_EXCLUDES "*gcc*" "*iutest*" "*/usr/include/*" "*mingw*") + SETUP_TARGET_FOR_COVERAGE( + NAME test_coverage # New target name + EXECUTABLE test # Executable in PROJECT_BINARY_DIR + DEPENDENCIES test # Dependencies to build first + ) + option(STRING_SPLIT_ENABLE_COVERAGE_HTML "enable coverage result to html" TRUE) + option(STRING_SPLIT_ENABLE_COVERAGE_SEND "send coverage result" FALSE) + if(STRING_SPLIT_ENABLE_COVERAGE_HTML) + message("coverage result to html enabled") + SETUP_TARGET_FOR_COVERAGE_TO_HTML( + NAME test_coverage_to_html # New target name + INFO_FILE_NAME test_coverage.info.cleaned # coverage task result file name + DEPENDENCIES test_coverage # Dependencies(coverage task, etc...) + ) + endif() +endif() + +# +# Update compiler waring flags +# +if(MSVC AND NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + # Force to always compile with W4 + if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]") + string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4") + endif() +elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) + # Update if necessary + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-long-long -pedantic") +endif() + +# +# Compile +# +add_executable(test ${test_src}) + +# +# Link +# +if(WIN32) + target_link_libraries(test ws2_32) +endif() + +add_custom_target(run_test + COMMAND test + WORKING_DIRECTORY ${PROJECT_BINARY_DIR} + DEPENDS test + COMMENT "Execute produced executable." +) From c2ebc81fd5abc4f0e4c8b74e1a871e8435e64f3d Mon Sep 17 00:00:00 2001 From: yumetodo Date: Sat, 7 Jul 2018 21:42:03 +0900 Subject: [PATCH 25/68] fix(ci/cmake): s/test/basic_test/ to avoid cmake UB --- test/CMakeLists.txt | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 3d74fdd..ed5e2db 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -25,17 +25,17 @@ endif() # # Set our project name # -project(test) +project(basic_test) # # Source files # -set(test_src +set(basic_test_src "./test.cpp" ) if(CMAKE_CXX_STANDARD GREATER_EQUAL 17) message("C++17 sources enabled") - list(APPEND test_src "./test_cxx17_string_view.cpp") + list(APPEND basic_test_src "./test_cxx17_string_view.cpp") endif() if(STRING_SPLIT_ENABLE_COVERAGE) @@ -45,8 +45,8 @@ if(STRING_SPLIT_ENABLE_COVERAGE) set(COVERAGE_EXCLUDES "*gcc*" "*iutest*" "*/usr/include/*" "*mingw*") SETUP_TARGET_FOR_COVERAGE( NAME test_coverage # New target name - EXECUTABLE test # Executable in PROJECT_BINARY_DIR - DEPENDENCIES test # Dependencies to build first + EXECUTABLE basic_test # Executable in PROJECT_BINARY_DIR + DEPENDENCIES basic_test # Dependencies to build first ) option(STRING_SPLIT_ENABLE_COVERAGE_HTML "enable coverage result to html" TRUE) option(STRING_SPLIT_ENABLE_COVERAGE_SEND "send coverage result" FALSE) @@ -78,18 +78,18 @@ endif() # # Compile # -add_executable(test ${test_src}) +add_executable(basic_test ${basic_test_src}) # # Link # if(WIN32) - target_link_libraries(test ws2_32) + target_link_libraries(basic_test ws2_32) endif() add_custom_target(run_test - COMMAND test + COMMAND basic_test WORKING_DIRECTORY ${PROJECT_BINARY_DIR} - DEPENDS test + DEPENDS basic_test COMMENT "Execute produced executable." ) From 0adcc6e736b4a5dd6fa9e5ba303e9ffd70f3e228 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Sat, 7 Jul 2018 22:00:06 +0900 Subject: [PATCH 26/68] fix(ci/shippable): disable boost --- shippable.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shippable.yml b/shippable.yml index b979681..246e4c5 100644 --- a/shippable.yml +++ b/shippable.yml @@ -25,7 +25,7 @@ script: - export TEST_RESULT=../../../shippable/testresults/test_result.xml - export STD_VER=c++17 - if [ "${WANDBOX_COMPILER}" = 'clang-3.7.1' ] || [ "${WANDBOX_COMPILER}" = 'gcc-4.9.2' ]; then export STD_VER=c++14 ; fi - - python ./iuwandbox.py ${SRC} -c ${WANDBOX_COMPILER} --std ${STD_VER} --encoding utf-8-sig --verbose --junit ${TEST_RESULT} + - python ./iuwandbox.py ${SRC} -c ${WANDBOX_COMPILER} --std ${STD_VER} --encoding utf-8-sig --boost nothing --verbose --junit ${TEST_RESULT} env: matrix: From d4b5b6920d2f29deefd6601adf51f7c4e11651bc Mon Sep 17 00:00:00 2001 From: yumetodo Date: Sat, 7 Jul 2018 23:24:59 +0900 Subject: [PATCH 27/68] fix(ci/travis): specify correct coverage result file path --- .travis.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 74a8810..5d1fed4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -44,4 +44,7 @@ script: - make ci after_success: # Coverage - - if [ "${USE_COVERALLS}" = '1' ]; then lcoveralls --retry-count 3 ./build_debug/test/coverage.info.cleaned ; fi + - ls $TRAVIS_BUILD_DIR + - ls "$TRAVIS_BUILD_DIR/build_debug" + - ls "$TRAVIS_BUILD_DIR/build_debug/test" + - if [ "${USE_COVERALLS}" = '1' ]; then lcoveralls --retry-count 3 "$TRAVIS_BUILD_DIR/build_debug/test/test_coverage.info.cleaned" ; fi From b3d3c7931cfc3b3ce178728c9a0ceda345705c71 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Sun, 8 Jul 2018 13:12:28 +0900 Subject: [PATCH 28/68] chore(ci/travis): pass --debug to lcoveralls --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 5d1fed4..5997ec7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -47,4 +47,4 @@ after_success: - ls $TRAVIS_BUILD_DIR - ls "$TRAVIS_BUILD_DIR/build_debug" - ls "$TRAVIS_BUILD_DIR/build_debug/test" - - if [ "${USE_COVERALLS}" = '1' ]; then lcoveralls --retry-count 3 "$TRAVIS_BUILD_DIR/build_debug/test/test_coverage.info.cleaned" ; fi + - if [ "${USE_COVERALLS}" = '1' ]; then lcoveralls --debug --retry-count 3 "$TRAVIS_BUILD_DIR/build_debug/test/test_coverage.info.cleaned" ; fi From aa8d6a6714f653d0ae29e81db49ccf164f459cf1 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Sun, 8 Jul 2018 13:30:06 +0900 Subject: [PATCH 29/68] fix(ci/travis): run lcoveralls on --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 5997ec7..6a59e0e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -44,6 +44,8 @@ script: - make ci after_success: # Coverage + - pwd + - cd $TRAVIS_BUILD_DIR - ls $TRAVIS_BUILD_DIR - ls "$TRAVIS_BUILD_DIR/build_debug" - ls "$TRAVIS_BUILD_DIR/build_debug/test" From e0d9b515c58d114312658367a90fdfe927edb13c Mon Sep 17 00:00:00 2001 From: yumetodo Date: Sun, 8 Jul 2018 13:42:16 +0900 Subject: [PATCH 30/68] chore(ci/travis): revert to pass --debug to lcoveralls This reverts commit b3d3c7931cfc3b3ce178728c9a0ceda345705c71. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 6a59e0e..a77cf14 100644 --- a/.travis.yml +++ b/.travis.yml @@ -49,4 +49,4 @@ after_success: - ls $TRAVIS_BUILD_DIR - ls "$TRAVIS_BUILD_DIR/build_debug" - ls "$TRAVIS_BUILD_DIR/build_debug/test" - - if [ "${USE_COVERALLS}" = '1' ]; then lcoveralls --debug --retry-count 3 "$TRAVIS_BUILD_DIR/build_debug/test/test_coverage.info.cleaned" ; fi + - if [ "${USE_COVERALLS}" = '1' ]; then lcoveralls --retry-count 3 "$TRAVIS_BUILD_DIR/build_debug/test/test_coverage.info.cleaned" ; fi From 0423739ae08faa30cb19781e98630aeaa95b52b3 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Mon, 9 Jul 2018 21:44:35 +0900 Subject: [PATCH 31/68] fix(counter_iterator): std::iterator was deprecated from C++17 --- benchmark/constant_range_loop.hpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/benchmark/constant_range_loop.hpp b/benchmark/constant_range_loop.hpp index 4d491fd..092a3ac 100644 --- a/benchmark/constant_range_loop.hpp +++ b/benchmark/constant_range_loop.hpp @@ -8,10 +8,18 @@ Distributed under the Boost Software License, Version 1.0. #include #include #include +#if 201500 <= __cplusplus || (defined(_MSVC_LANG) && 201500 <= _MSVC_LANG) +# define CRL_CXX17_STD_ITERATPR_DEPRECATED +#endif template::value, std::nullptr_t> = nullptr> -class counter_iterator : std::iterator { +class counter_iterator +#ifndef CRL_CXX17_STD_ITERATPR_DEPRECATED + : std::iterator +#endif +{ private: T i; +#ifndef CRL_CXX17_STD_ITERATPR_DEPRECATED typedef std::iterator my_t; public: typedef typename my_t::iterator_category iterator_category; @@ -20,6 +28,14 @@ class counter_iterator : std::iterator { typedef typename my_t::pointer pointer; typedef typename my_t::reference reference; +#else +public: + using iterator_category = std::random_access_iterator_tag; + using value_type = T; + using difference_type = T; + using pointer = T*; + using reference = T&; +#endif constexpr counter_iterator() : i() { } constexpr counter_iterator(T n) : i(n) { } counter_iterator& operator=(const counter_iterator& o) noexcept { From cf47f04e40b90c419340250b6107097a1223d6f4 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Mon, 9 Jul 2018 21:45:34 +0900 Subject: [PATCH 32/68] chore(benchmark): ignore compiler warnings --- benchmark/benchmark.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/benchmark/benchmark.cpp b/benchmark/benchmark.cpp index abe0339..eaefc06 100644 --- a/benchmark/benchmark.cpp +++ b/benchmark/benchmark.cpp @@ -121,9 +121,12 @@ std::string generate_random_string(std::size_t len, std::size_t split_num, char void benchmark_split_only(split_func_t split_f, const char* func_name, const std::string& s, char delim, std::size_t cnt) { namespace ch = std::chrono; const auto t_start = ch::high_resolution_clock::now(); +#pragma warning(push) +#pragma warning(disable: 5030) for ([[gnu::unused]] auto&& i : rep(cnt - 1)) { split_f(s, delim); } +#pragma warning(pop) const auto re = split_f(s, delim); const auto t_stop = ch::high_resolution_clock::now(); std::cout @@ -146,13 +149,13 @@ void benchmark_split_extract(split_func_t split_f, const char* func_name, const std::string re; if (split_our_library == split_f) { for ([[gnu::unused]] auto&& i : rep(cnt - 1)) { - s | split(delim)[extract_i]; + (void)(s | split(delim)[extract_i]); } re = s | split(delim)[extract_i]; } else { for ([[gnu::unused]] auto&& i : rep(cnt - 1)) { - split_f(s, delim)[extract_i]; + (void)split_f(s, delim)[extract_i]; } re = split_f(s, delim)[extract_i]; } From 44461dd44d1d49fea5ba7c2dda784f9fd31569f3 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Mon, 9 Jul 2018 22:10:56 +0900 Subject: [PATCH 33/68] feat(test/.at_first.front): add test --- test/test_cxx17_string_view.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/test/test_cxx17_string_view.cpp b/test/test_cxx17_string_view.cpp index a3a4240..4c87ac3 100644 --- a/test/test_cxx17_string_view.cpp +++ b/test/test_cxx17_string_view.cpp @@ -1,4 +1,4 @@ -#include "../include/string_split.hpp" +#include "../include/string_split.hpp" #ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW #include "../iutest/include/iutest.hpp" #include "constant.hpp" @@ -64,6 +64,14 @@ IUTEST_TYPED_TEST(StringViewSplit, chain_back_by_stl_str_view) const std::basic_string_view delim = constant::space_underscore(); IUTEST_ASSERT_EQ(constant::world(), s | split(delim) >> back()); } +IUTEST_TYPED_TEST(StringViewSplit, chain_at_first_front) +{ + using char_type = TypeParam; + const std::basic_string_view s = constant::cpp_type_data2(); + const auto re = s | split(constant::space()) >> at_first().front(); + IUTEST_ASSERT_EQ(constant::cpp_dxle_sound_c(), re); +} +IUTEST_TYPED_TEST(StringViewSplit, chain_at_first_back_by_single_char) IUTEST_TYPED_TEST(StringViewSplit, ExtractBySingeChar) { using char_type = TypeParam; From b7b09e6fb85894f317e822218b4ac3c1e10538e6 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Mon, 9 Jul 2018 22:11:42 +0900 Subject: [PATCH 34/68] feat(.at_first.back): add impl --- include/string_split.hpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/string_split.hpp b/include/string_split.hpp index d336441..cca10da 100644 --- a/include/string_split.hpp +++ b/include/string_split.hpp @@ -285,9 +285,19 @@ namespace detail { return (StrType::npos == pos) ? str : str.substr(str.find_last_of(info.delim) + 1); } //at_first().back()の時 +#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW + template< + typename StrType, typename DelimType, typename CharType, + enable_if_t, std::nullptr_t> = nullptr + > + StrType operator| (const StrType& str, const split_helper_subroutine& info) noexcept(type_traits::is_stl_string_view_v) + { +#else template b_str operator| (const b_str& str, const split_helper_subroutine& info) { + using StrType = b_str; +#endif const auto pos = str.find_first_of(info.delim); if (b_str::npos == pos) return {}; return str.substr(str.find_first_not_of(info.delim, pos)); From 8bb1ef668bc0aaa28af6d3df72922cc833588611 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Mon, 9 Jul 2018 22:12:21 +0900 Subject: [PATCH 35/68] feat(test/.at_first.back): add test --- test/test.cpp | 9 +++++++++ test/test_cxx17_string_view.cpp | 29 ++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/test/test.cpp b/test/test.cpp index 751f5b0..0a0bc32 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -101,6 +101,15 @@ IUTEST_TYPED_TEST(StringSplitLvalue, chain_at_first_back_by_stl_str) const auto re = s | split(std::basic_string(constant::space_underscore())) >> at_first().back(); IUTEST_ASSERT_EQ(constant::na_world(), re); } +#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW +IUTEST_TYPED_TEST(StringSplitLvalue, chain_at_first_back_by_stl_str_view) +{ + using char_type = TypeParam; + const std::basic_string s = constant::arikitari_na_world_underscore(); + const auto re = s | split(std::basic_string_view(constant::space_underscore())) >> at_first().back(); + IUTEST_ASSERT_EQ(constant::na_world(), re); +} +#endif IUTEST_TYPED_TEST(StringSplitLvalue, chain_at_first_by_single_char) { using char_type = TypeParam; diff --git a/test/test_cxx17_string_view.cpp b/test/test_cxx17_string_view.cpp index 4c87ac3..39ec7fe 100644 --- a/test/test_cxx17_string_view.cpp +++ b/test/test_cxx17_string_view.cpp @@ -1,4 +1,4 @@ -#include "../include/string_split.hpp" +#include "../include/string_split.hpp" #ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW #include "../iutest/include/iutest.hpp" #include "constant.hpp" @@ -72,6 +72,33 @@ IUTEST_TYPED_TEST(StringViewSplit, chain_at_first_front) IUTEST_ASSERT_EQ(constant::cpp_dxle_sound_c(), re); } IUTEST_TYPED_TEST(StringViewSplit, chain_at_first_back_by_single_char) +{ + using char_type = TypeParam; + const std::basic_string_view s = constant::cpp_type_data2(); + const auto re = s | split(constant::space()) >> at_first().back(); + IUTEST_ASSERT_EQ(constant::cpp_LoadSoundMem(), re); +} +IUTEST_TYPED_TEST(StringViewSplit, chain_at_first_back_by_c_str) +{ + using char_type = TypeParam; + const std::basic_string_view s = constant::arikitari_na_world_underscore(); + const auto re = s | split(constant::space_underscore()) >> at_first().back(); + IUTEST_ASSERT_EQ(constant::na_world(), re); +} +IUTEST_TYPED_TEST(StringViewSplit, chain_at_first_back_by_stl_str) +{ + using char_type = TypeParam; + const std::basic_string_view s = constant::arikitari_na_world_underscore(); + const auto re = s | split(std::basic_string(constant::space_underscore())) >> at_first().back(); + IUTEST_ASSERT_EQ(constant::na_world(), re); +} +IUTEST_TYPED_TEST(StringViewSplit, chain_at_first_back_by_stl_str_view) +{ + using char_type = TypeParam; + const std::basic_string_view s = constant::arikitari_na_world_underscore(); + const auto re = s | split(std::basic_string_view(constant::space_underscore())) >> at_first().back(); + IUTEST_ASSERT_EQ(constant::na_world(), re); +} IUTEST_TYPED_TEST(StringViewSplit, ExtractBySingeChar) { using char_type = TypeParam; From 523c0af4e1820a1146916a629fb1732fc30f0545 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Mon, 9 Jul 2018 22:36:24 +0900 Subject: [PATCH 36/68] fix(.at_first.back): s/b_str/StrType/ --- include/string_split.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/string_split.hpp b/include/string_split.hpp index cca10da..94de8fb 100644 --- a/include/string_split.hpp +++ b/include/string_split.hpp @@ -1,4 +1,4 @@ -/*============================================================================= +/*============================================================================= Copyright (C) 2016-2018 yumetodo Distributed under the Boost Software License, Version 1.0. @@ -299,7 +299,7 @@ namespace detail { using StrType = b_str; #endif const auto pos = str.find_first_of(info.delim); - if (b_str::npos == pos) return {}; + if (StrType::npos == pos) return {}; return str.substr(str.find_first_not_of(info.delim, pos)); } //at_first()の時 From 10ce93f3dab870e61b7132f9345f5c1755a9f820 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Mon, 9 Jul 2018 22:37:02 +0900 Subject: [PATCH 37/68] feat(.at_first): add impl --- include/string_split.hpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/include/string_split.hpp b/include/string_split.hpp index 94de8fb..dac0b84 100644 --- a/include/string_split.hpp +++ b/include/string_split.hpp @@ -1,4 +1,4 @@ -/*============================================================================= +/*============================================================================= Copyright (C) 2016-2018 yumetodo Distributed under the Boost Software License, Version 1.0. @@ -303,11 +303,21 @@ namespace detail { return str.substr(str.find_first_not_of(info.delim, pos)); } //at_first()の時 +#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW + template< + typename StrType, typename DelimType, typename CharType, + enable_if_t, std::nullptr_t> = nullptr + > + std::array operator| (const StrType& str, const split_helper_subroutine& info) noexcept(type_traits::is_stl_string_view_v) + { +#else template std::array, 2> operator| (const b_str& str, const split_helper_subroutine& info) { + using StrType = b_str; +#endif const auto pos = str.find_first_of(info.delim); - if (b_str::npos == pos) return{ { str, {} } }; + if (StrType::npos == pos) return{ { str, {} } }; return{ {str.substr(0, pos), str.substr(str.find_first_not_of(info.delim, pos))} }; } //at_last().front()の時 From 0dae00866f39aa31b3aedfba19fc845d9efda75d Mon Sep 17 00:00:00 2001 From: yumetodo Date: Mon, 9 Jul 2018 22:37:19 +0900 Subject: [PATCH 38/68] feat(test/.at_first): add test --- test/test.cpp | 11 ++++++++++ test/test_cxx17_string_view.cpp | 36 +++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/test/test.cpp b/test/test.cpp index 0a0bc32..9b6e563 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -137,6 +137,17 @@ IUTEST_TYPED_TEST(StringSplitLvalue, chain_at_first_by_stl_str) IUTEST_ASSERT_EQ(constant::arikitari(), re[0]); IUTEST_ASSERT_EQ(constant::na_world(), re[1]); } +#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW +IUTEST_TYPED_TEST(StringSplitLvalue, chain_at_first_by_stl_str_view) +{ + using char_type = TypeParam; + const std::basic_string s = constant::arikitari_na_world_underscore(); + const auto re = s | split(std::basic_string_view(constant::space_underscore())) >> at_first(); + IUTEST_ASSERT(2u == re.size()); + IUTEST_ASSERT_EQ(constant::arikitari(), re[0]); + IUTEST_ASSERT_EQ(constant::na_world(), re[1]); +} +#endif IUTEST_TYPED_TEST(StringSplitLvalue, chain_at_last_front_by_single_char) { using char_type = TypeParam; diff --git a/test/test_cxx17_string_view.cpp b/test/test_cxx17_string_view.cpp index 39ec7fe..59e0061 100644 --- a/test/test_cxx17_string_view.cpp +++ b/test/test_cxx17_string_view.cpp @@ -99,6 +99,42 @@ IUTEST_TYPED_TEST(StringViewSplit, chain_at_first_back_by_stl_str_view) const auto re = s | split(std::basic_string_view(constant::space_underscore())) >> at_first().back(); IUTEST_ASSERT_EQ(constant::na_world(), re); } +IUTEST_TYPED_TEST(StringViewSplit, chain_at_first_by_single_char) +{ + using char_type = TypeParam; + const std::basic_string_view s = constant::cpp_type_data2(); + const auto re = s | split(constant::space()) >> at_first(); + IUTEST_ASSERT(2u == re.size()); + IUTEST_ASSERT_EQ(constant::cpp_dxle_sound_c(), re[0]); + IUTEST_ASSERT_EQ(constant::cpp_LoadSoundMem(), re[1]); +} +IUTEST_TYPED_TEST(StringViewSplit, chain_at_first_by_c_str) +{ + using char_type = TypeParam; + const std::basic_string_view s = constant::arikitari_na_world_underscore(); + const auto re = s | split(constant::space_underscore()) >> at_first(); + IUTEST_ASSERT(2u == re.size()); + IUTEST_ASSERT_EQ(constant::arikitari(), re[0]); + IUTEST_ASSERT_EQ(constant::na_world(), re[1]); +} +IUTEST_TYPED_TEST(StringViewSplit, chain_at_first_by_stl_str) +{ + using char_type = TypeParam; + const std::basic_string_view s = constant::arikitari_na_world_underscore(); + const auto re = s | split(std::basic_string(constant::space_underscore())) >> at_first(); + IUTEST_ASSERT(2u == re.size()); + IUTEST_ASSERT_EQ(constant::arikitari(), re[0]); + IUTEST_ASSERT_EQ(constant::na_world(), re[1]); +} +IUTEST_TYPED_TEST(StringViewSplit, chain_at_first_by_stl_str_view) +{ + using char_type = TypeParam; + const std::basic_string_view s = constant::arikitari_na_world_underscore(); + const auto re = s | split(std::basic_string_view(constant::space_underscore())) >> at_first(); + IUTEST_ASSERT(2u == re.size()); + IUTEST_ASSERT_EQ(constant::arikitari(), re[0]); + IUTEST_ASSERT_EQ(constant::na_world(), re[1]); +} IUTEST_TYPED_TEST(StringViewSplit, ExtractBySingeChar) { using char_type = TypeParam; From 2ca3a8506b25f2421992a5b6519e16be6e7ab50e Mon Sep 17 00:00:00 2001 From: yumetodo Date: Mon, 9 Jul 2018 22:53:44 +0900 Subject: [PATCH 39/68] feat(.at_last.front): add impl --- include/string_split.hpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/include/string_split.hpp b/include/string_split.hpp index dac0b84..1932800 100644 --- a/include/string_split.hpp +++ b/include/string_split.hpp @@ -321,11 +321,21 @@ namespace detail { return{ {str.substr(0, pos), str.substr(str.find_first_not_of(info.delim, pos))} }; } //at_last().front()の時 +#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW + template< + typename StrType, typename DelimType, typename CharType, + enable_if_t, std::nullptr_t> = nullptr + > + StrType operator| (const StrType& str, const split_helper_subroutine& info) noexcept(type_traits::is_stl_string_view_v) + { +#else template b_str operator| (const b_str& str, const split_helper_subroutine& info) { + using StrType = b_str; +#endif const auto pos = str.find_last_of(info.delim); - if (b_str::npos == pos) return {}; + if (StrType::npos == pos) return {}; return str.substr(0, str.find_last_not_of(info.delim, pos) + 1); } //at_last()の時 From 03784c1c7e1022a460edc5244df6cd8083fd4d39 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Mon, 9 Jul 2018 22:54:06 +0900 Subject: [PATCH 40/68] feat(test/.at_last.front): add test --- test/test.cpp | 9 +++++++++ test/test_cxx17_string_view.cpp | 28 ++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/test/test.cpp b/test/test.cpp index 9b6e563..61ee32e 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -169,6 +169,15 @@ IUTEST_TYPED_TEST(StringSplitLvalue, chain_at_last_front_by_stl_str) const auto re = s | split(std::basic_string(constant::space_underscore())) >> at_last().front(); IUTEST_ASSERT_EQ(constant::arikitari_na(), re); } +#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW +IUTEST_TYPED_TEST(StringSplitLvalue, chain_at_last_front_by_stl_str_view) +{ + using char_type = TypeParam; + const std::basic_string s = constant::arikitari_na_world_underscore(); + const auto re = s | split(std::basic_string_view(constant::space_underscore())) >> at_last().front(); + IUTEST_ASSERT_EQ(constant::arikitari_na(), re); +} +#endif IUTEST_TYPED_TEST(StringSplitLvalue, chain_at_last_back) { using char_type = TypeParam; diff --git a/test/test_cxx17_string_view.cpp b/test/test_cxx17_string_view.cpp index 59e0061..c3e805a 100644 --- a/test/test_cxx17_string_view.cpp +++ b/test/test_cxx17_string_view.cpp @@ -135,6 +135,34 @@ IUTEST_TYPED_TEST(StringViewSplit, chain_at_first_by_stl_str_view) IUTEST_ASSERT_EQ(constant::arikitari(), re[0]); IUTEST_ASSERT_EQ(constant::na_world(), re[1]); } +IUTEST_TYPED_TEST(StringViewSplit, chain_at_last_front_by_single_char) +{ + using char_type = TypeParam; + const std::basic_string_view s = constant::cpp_type_data1(); + const auto re = s | split(constant::colon()) >> at_last().front(); + IUTEST_ASSERT_EQ(constant::cpp_basic_istream(), re); +} +IUTEST_TYPED_TEST(StringViewSplit, chain_at_last_front_by_c_str) +{ + using char_type = TypeParam; + const std::basic_string_view s = constant::arikitari_na_world_underscore(); + const auto re = s | split(constant::space_underscore()) >> at_last().front(); + IUTEST_ASSERT_EQ(constant::arikitari_na(), re); +} +IUTEST_TYPED_TEST(StringViewSplit, chain_at_last_front_by_stl_str) +{ + using char_type = TypeParam; + const std::basic_string_view s = constant::arikitari_na_world_underscore(); + const auto re = s | split(std::basic_string(constant::space_underscore())) >> at_last().front(); + IUTEST_ASSERT_EQ(constant::arikitari_na(), re); +} +IUTEST_TYPED_TEST(StringViewSplit, chain_at_last_front_by_stl_str_view) +{ + using char_type = TypeParam; + const std::basic_string_view s = constant::arikitari_na_world_underscore(); + const auto re = s | split(std::basic_string_view(constant::space_underscore())) >> at_last().front(); + IUTEST_ASSERT_EQ(constant::arikitari_na(), re); +} IUTEST_TYPED_TEST(StringViewSplit, ExtractBySingeChar) { using char_type = TypeParam; From aadf9e3f637f5afe9b99383daea49a6a9a2b88d3 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Tue, 10 Jul 2018 20:11:02 +0900 Subject: [PATCH 41/68] feat(test/.at_first.back): add test --- test/test_cxx17_string_view.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/test_cxx17_string_view.cpp b/test/test_cxx17_string_view.cpp index c3e805a..2a3b70a 100644 --- a/test/test_cxx17_string_view.cpp +++ b/test/test_cxx17_string_view.cpp @@ -163,6 +163,13 @@ IUTEST_TYPED_TEST(StringViewSplit, chain_at_last_front_by_stl_str_view) const auto re = s | split(std::basic_string_view(constant::space_underscore())) >> at_last().front(); IUTEST_ASSERT_EQ(constant::arikitari_na(), re); } +IUTEST_TYPED_TEST(StringViewSplit, chain_at_last_back) +{ + using char_type = TypeParam; + const std::basic_string_view s = constant::cpp_type_data1(); + const auto re = s | split(constant::colon()) >> at_last().back(); + IUTEST_ASSERT_EQ(constant::ignore(), re); +} IUTEST_TYPED_TEST(StringViewSplit, ExtractBySingeChar) { using char_type = TypeParam; From 70e33b3c06d29eebe28d27903b59fd279880b277 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Tue, 10 Jul 2018 20:11:57 +0900 Subject: [PATCH 42/68] fix(CodeCoverage): register coverage result to clean --- cmake/modules/CodeCoverage.cmake | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmake/modules/CodeCoverage.cmake b/cmake/modules/CodeCoverage.cmake index d88a728..99a3a12 100644 --- a/cmake/modules/CodeCoverage.cmake +++ b/cmake/modules/CodeCoverage.cmake @@ -168,6 +168,8 @@ function(SETUP_TARGET_FOR_COVERAGE) COMMENT "Resetting code coverage counters to zero.\nProcessing code coverage counters and generating report." ) + # Register to clean coverage result + set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${Coverage_NAME}.info ${Coverage_NAME}.info.cleaned) # Show where to find the lcov info report add_custom_command(TARGET ${Coverage_NAME} POST_BUILD COMMAND ; From 59db2c297919de44640fdf4aea34d99ddc3549c8 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Tue, 10 Jul 2018 20:29:09 +0900 Subject: [PATCH 43/68] feat(.at_last): add impl --- include/string_split.hpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/include/string_split.hpp b/include/string_split.hpp index 1932800..2746633 100644 --- a/include/string_split.hpp +++ b/include/string_split.hpp @@ -339,11 +339,21 @@ namespace detail { return str.substr(0, str.find_last_not_of(info.delim, pos) + 1); } //at_last()の時 +#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW + template< + typename StrType, typename DelimType, typename CharType, + enable_if_t, std::nullptr_t> = nullptr + > + std::array operator| (const StrType& str, const split_helper_subroutine& info) noexcept(type_traits::is_stl_string_view_v) + { +#else template std::array, 2> operator| (const b_str& str, const split_helper_subroutine& info) { + using StrType = b_str; +#endif const auto pos = str.find_last_of(info.delim); - if (b_str::npos == pos) return{ { {}, str } }; + if (StrType::npos == pos) return{ { {}, str } }; return { { str.substr(0, str.find_last_not_of(info.delim, pos) + 1), str.substr(pos + 1) } }; } //区切り文字1文字, operator[] or front()の時 From 87e2cca5f7deecd9e1647ed4ef78713943323ff9 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Tue, 10 Jul 2018 20:30:37 +0900 Subject: [PATCH 44/68] feat(test/.at_last): add test --- test/test.cpp | 11 ++++++++++ test/test_cxx17_string_view.cpp | 38 ++++++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/test/test.cpp b/test/test.cpp index 61ee32e..beccd38 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -212,6 +212,17 @@ IUTEST_TYPED_TEST(StringSplitLvalue, chain_at_last_by_stl_str) IUTEST_ASSERT_EQ(constant::arikitari_na(), re[0]); IUTEST_ASSERT_EQ(constant::world(), re[1]); } +#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW +IUTEST_TYPED_TEST(StringSplitLvalue, chain_at_last_by_stl_str_view) +{ + using char_type = TypeParam; + const std::basic_string s = constant::arikitari_na_world_underscore(); + const auto re = s | split(std::basic_string_view(constant::space_underscore())) >> at_last(); + IUTEST_ASSERT(2u == re.size()); + IUTEST_ASSERT_EQ(constant::arikitari_na(), re[0]); + IUTEST_ASSERT_EQ(constant::world(), re[1]); +} +#endif IUTEST_TYPED_TEST(StringSplitLvalue, ExtractBySingeChar) { using char_type = TypeParam; diff --git a/test/test_cxx17_string_view.cpp b/test/test_cxx17_string_view.cpp index 2a3b70a..d348cdb 100644 --- a/test/test_cxx17_string_view.cpp +++ b/test/test_cxx17_string_view.cpp @@ -1,4 +1,4 @@ -#include "../include/string_split.hpp" +#include "../include/string_split.hpp" #ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW #include "../iutest/include/iutest.hpp" #include "constant.hpp" @@ -170,6 +170,42 @@ IUTEST_TYPED_TEST(StringViewSplit, chain_at_last_back) const auto re = s | split(constant::colon()) >> at_last().back(); IUTEST_ASSERT_EQ(constant::ignore(), re); } +IUTEST_TYPED_TEST(StringViewSplit, chain_at_last_by_single_char) +{ + using char_type = TypeParam; + const std::basic_string_view s = constant::cpp_type_data1(); + const auto re = s | split(constant::colon()) >> at_last(); + IUTEST_ASSERT(2u == re.size()); + IUTEST_ASSERT_EQ(constant::cpp_basic_istream(), re[0]); + IUTEST_ASSERT_EQ(constant::ignore(), re[1]); +} +IUTEST_TYPED_TEST(StringViewSplit, chain_at_last_by_c_str) +{ + using char_type = TypeParam; + const std::basic_string_view s = constant::arikitari_na_world_underscore(); + const auto re = s | split(constant::space_underscore()) >> at_last(); + IUTEST_ASSERT(2u == re.size()); + IUTEST_ASSERT_EQ(constant::arikitari_na(), re[0]); + IUTEST_ASSERT_EQ(constant::world(), re[1]); +} +IUTEST_TYPED_TEST(StringViewSplit, chain_at_last_by_stl_str) +{ + using char_type = TypeParam; + const std::basic_string_view s = constant::arikitari_na_world_underscore(); + const auto re = s | split(std::basic_string(constant::space_underscore())) >> at_last(); + IUTEST_ASSERT(2u == re.size()); + IUTEST_ASSERT_EQ(constant::arikitari_na(), re[0]); + IUTEST_ASSERT_EQ(constant::world(), re[1]); +} +IUTEST_TYPED_TEST(StringViewSplit, chain_at_last_by_stl_str_view) +{ + using char_type = TypeParam; + const std::basic_string_view s = constant::arikitari_na_world_underscore(); + const auto re = s | split(std::basic_string_view(constant::space_underscore())) >> at_last(); + IUTEST_ASSERT(2u == re.size()); + IUTEST_ASSERT_EQ(constant::arikitari_na(), re[0]); + IUTEST_ASSERT_EQ(constant::world(), re[1]); +} IUTEST_TYPED_TEST(StringViewSplit, ExtractBySingeChar) { using char_type = TypeParam; From 992f2d6e36412231b938f11d4d7a1bde1e6b597f Mon Sep 17 00:00:00 2001 From: yumetodo Date: Tue, 10 Jul 2018 21:09:29 +0900 Subject: [PATCH 45/68] fix(test/single-delim, op[] | front()): use string_view --- test/test_cxx17_string_view.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_cxx17_string_view.cpp b/test/test_cxx17_string_view.cpp index d348cdb..08527d0 100644 --- a/test/test_cxx17_string_view.cpp +++ b/test/test_cxx17_string_view.cpp @@ -1,4 +1,4 @@ -#include "../include/string_split.hpp" +#include "../include/string_split.hpp" #ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW #include "../iutest/include/iutest.hpp" #include "constant.hpp" @@ -210,7 +210,7 @@ IUTEST_TYPED_TEST(StringViewSplit, ExtractBySingeChar) { using char_type = TypeParam; constexpr char_type space = constant::space(); - const std::basic_string s = constant::arikitari_na_world(); + const std::basic_string_view s = constant::arikitari_na_world(); IUTEST_ASSERT_EQ(constant::arikitari(), s | split(space)[0]); IUTEST_ASSERT_EQ(constant::na(), s | split(space)[1]); IUTEST_ASSERT_EQ(constant::world(), s | split(space)[2]); From e90fdcbb98a5a679a95a89eab580f330fb583314 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Tue, 10 Jul 2018 21:43:44 +0900 Subject: [PATCH 46/68] feat(multi-delim): add impl --- include/string_split.hpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/include/string_split.hpp b/include/string_split.hpp index 2746633..47fc3fa 100644 --- a/include/string_split.hpp +++ b/include/string_split.hpp @@ -517,6 +517,17 @@ namespace detail { return re; } //区切り文字複数の時 +#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW + template< + typename StrType, typename DelimType, bool is_c_str, bool is_stl_string, + enable_if_t::char_type + >, std::nullptr_t> = nullptr + > + auto operator| (const StrType& str, const split_helper& info) -> vector + { +#else template auto operator| (const b_str& str, const split_helper& info) -> enable_if_t< @@ -524,11 +535,13 @@ namespace detail { vector> > { - vector> re; + using StrType = b_str; +#endif + vector re; size_t current = 0; for ( size_t found = str.find_first_of(info.delim, current); - current != b_str::npos && found != b_str::npos; + current != StrType::npos && found != StrType::npos; current = str.find_first_not_of(info.delim, found + 1), found = str.find_first_of(info.delim, current) ) { if (re.capacity() < re.size() + 1) re.reserve((std::numeric_limits::max() / 2 < re.size()) ? std::numeric_limits::max() : re.size() * 2); From 27fef4d24a1b9bd0ae55ce98ea681621976d5cf9 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Tue, 10 Jul 2018 21:44:19 +0900 Subject: [PATCH 47/68] feat(test/multi-delim): add test --- test/test.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/test.cpp b/test/test.cpp index beccd38..07f7a48 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -343,6 +343,22 @@ IUTEST_TYPED_TEST(StringSplitLvalue, SplitByStlStr) IUTEST_ASSERT_TRUE(std::equal(std::begin(re1_1), std::end(re1_1), re1_2.begin(), re1_2.end())); StringSplitLvalue_SplitByStlStr::without_char(); } +#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW +IUTEST_TYPED_TEST(StringSplitLvalue, SplitByStlStrView) +{ + using char_type = TypeParam; + const std::basic_string s1 = constant::arikitari_na_world_underscore(); + const std::basic_string re1_1[] = { constant::arikitari(), constant::na(), constant::world() }; + const auto re1_2 = s1 | split(std::basic_string_view(constant::space_underscore())); + IUTEST_ASSERT_TRUE(std::equal(std::begin(re1_1), std::end(re1_1), re1_2.begin(), re1_2.end())); + if constexpr(!std::is_same_v) { + const std::basic_string s2 = constant::arikitarina_sekai_wspace(); + const std::basic_string re2_1[] = { constant::arikitarina(), constant::sekai() }; + const auto re2_2 = s2 | split(std::basic_string(constant::wspace())); + IUTEST_ASSERT_TRUE(std::equal(std::begin(re2_1), std::end(re2_1), re2_2.begin(), re2_2.end())); + } +} +#endif template struct StringSplitLvalueCovertToInt : public ::iutest::Test {}; IUTEST_TYPED_TEST_CASE(StringSplitLvalueCovertToInt, ::iutest::Types); From c4fbe26a9cc1c115630f14a71d6874b95bead8e4 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Tue, 10 Jul 2018 22:31:14 +0900 Subject: [PATCH 48/68] fix(test/multi-delim): add test --- test/test_cxx17_string_view.cpp | 44 ++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/test/test_cxx17_string_view.cpp b/test/test_cxx17_string_view.cpp index 08527d0..f7bdaa9 100644 --- a/test/test_cxx17_string_view.cpp +++ b/test/test_cxx17_string_view.cpp @@ -1,4 +1,4 @@ -#include "../include/string_split.hpp" +#include "../include/string_split.hpp" #ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW #include "../iutest/include/iutest.hpp" #include "constant.hpp" @@ -259,3 +259,45 @@ IUTEST_TYPED_TEST(StringViewSplit, ExtractByStlStrView) IUTEST_EXPECT_THROW(s | split(delim)[std::numeric_limits::max()], std::out_of_range); } #endif +IUTEST_TYPED_TEST(StringViewSplit, SplitByCStr) +{ + using char_type = TypeParam; + const std::basic_string_view s1 = constant::arikitari_na_world_underscore(); + const std::basic_string_view re1_1[] = { constant::arikitari(), constant::na(), constant::world() }; + const auto re1_2 = s1 | split(constant::space_underscore()); + IUTEST_ASSERT_TRUE(std::equal(std::begin(re1_1), std::end(re1_1), re1_2.begin(), re1_2.end())); + if constexpr(!std::is_same_v) { + const std::basic_string_view s2 = constant::arikitarina_sekai_wspace(); + const std::basic_string_view re2_1[] = { constant::arikitarina(), constant::sekai() }; + const auto re2_2 = s2 | split(constant::wspace()); + IUTEST_ASSERT_TRUE(std::equal(std::begin(re2_1), std::end(re2_1), re2_2.begin(), re2_2.end())); + } +} +IUTEST_TYPED_TEST(StringViewSplit, SplitByStlStr) +{ + using char_type = TypeParam; + const std::basic_string_view s1 = constant::arikitari_na_world_underscore(); + const std::basic_string_view re1_1[] = { constant::arikitari(), constant::na(), constant::world() }; + const auto re1_2 = s1 | split(std::basic_string(constant::space_underscore())); + IUTEST_ASSERT_TRUE(std::equal(std::begin(re1_1), std::end(re1_1), re1_2.begin(), re1_2.end())); + if constexpr(!std::is_same_v) { + const std::basic_string_view s2 = constant::arikitarina_sekai_wspace(); + const std::basic_string_view re2_1[] = { constant::arikitarina(), constant::sekai() }; + const auto re2_2 = s2 | split(std::basic_string(constant::wspace())); + IUTEST_ASSERT_TRUE(std::equal(std::begin(re2_1), std::end(re2_1), re2_2.begin(), re2_2.end())); + } +} +IUTEST_TYPED_TEST(StringViewSplit, SplitByStlStrView) +{ + using char_type = TypeParam; + const std::basic_string_view s1 = constant::arikitari_na_world_underscore(); + const std::basic_string_view re1_1[] = { constant::arikitari(), constant::na(), constant::world() }; + const auto re1_2 = s1 | split(std::basic_string_view(constant::space_underscore())); + IUTEST_ASSERT_TRUE(std::equal(std::begin(re1_1), std::end(re1_1), re1_2.begin(), re1_2.end())); + if constexpr(!std::is_same_v) { + const std::basic_string_view s2 = constant::arikitarina_sekai_wspace(); + const std::basic_string_view re2_1[] = { constant::arikitarina(), constant::sekai() }; + const auto re2_2 = s2 | split(std::basic_string(constant::wspace())); + IUTEST_ASSERT_TRUE(std::equal(std::begin(re2_1), std::end(re2_1), re2_2.begin(), re2_2.end())); + } +} From f1460e7c417576a46a5e70a41ecedeabe423e511 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Tue, 10 Jul 2018 22:32:25 +0900 Subject: [PATCH 49/68] fix(multi-delim): string_veiw ctor has no ability to create substr --- include/string_split.hpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/include/string_split.hpp b/include/string_split.hpp index 47fc3fa..2868713 100644 --- a/include/string_split.hpp +++ b/include/string_split.hpp @@ -1,4 +1,4 @@ -/*============================================================================= +/*============================================================================= Copyright (C) 2016-2018 yumetodo Distributed under the Boost Software License, Version 1.0. @@ -456,6 +456,18 @@ namespace detail { re.push_back(info.f(std::basic_string(str, current, str.size() - current))); return re; } +#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW + template + void vector_emplace_make_substr(vector>& re, const b_str_view& str, size_t pos, size_t n) + { + re.emplace_back(str.substr(pos, n)); + } +#endif + template + void vector_emplace_make_substr(vector>& re, const b_str& str, size_t pos, size_t n) + { + re.emplace_back(str, pos, n); + } //区切り文字1文字の時 template vector> operator| (const b_str& str, const split_helper& info) @@ -545,9 +557,9 @@ namespace detail { current = str.find_first_not_of(info.delim, found + 1), found = str.find_first_of(info.delim, current) ) { if (re.capacity() < re.size() + 1) re.reserve((std::numeric_limits::max() / 2 < re.size()) ? std::numeric_limits::max() : re.size() * 2); - re.emplace_back(str, current, found - current); + vector_emplace_make_substr(re, str, current, found - current); } - re.emplace_back(str, current, str.size() - current); + vector_emplace_make_substr(re, str, current, str.size() - current); return re; } //back()の時 From 125b93e6688b6525b670ed6b9d31c4d151e7d8b7 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Tue, 10 Jul 2018 23:15:35 +0900 Subject: [PATCH 50/68] feat(single-delim): add impl --- include/string_split.hpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/include/string_split.hpp b/include/string_split.hpp index 2868713..a7429c0 100644 --- a/include/string_split.hpp +++ b/include/string_split.hpp @@ -1,4 +1,4 @@ -/*============================================================================= +/*============================================================================= Copyright (C) 2016-2018 yumetodo Distributed under the Boost Software License, Version 1.0. @@ -469,16 +469,26 @@ namespace detail { re.emplace_back(str, pos, n); } //区切り文字1文字の時 +#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW + template< + typename StrType, typename CharType, + enable_if_t, std::nullptr_t> = nullptr + > + vector operator| (const StrType& str, const split_helper& info) + { +#else template vector> operator| (const b_str& str, const split_helper& info) { - vector> re; + using StrType = b_str; +#endif + vector re; size_t current = 0; - for (size_t found; (found = str.find_first_of(info.delim, current)) != b_str::npos; current = found + 1) { + for (size_t found; (found = str.find_first_of(info.delim, current)) != StrType::npos; current = found + 1) { if (re.capacity() < re.size() + 1) re.reserve((std::numeric_limits::max() / 2 < re.size()) ? std::numeric_limits::max() : re.size() * 2); - re.emplace_back(str, current, found - current); + vector_emplace_make_substr(re, str, current, found - current); } - re.emplace_back(str, current, str.size() - current); + vector_emplace_make_substr(re, str, current, str.size() - current); return re; } //区切り文字複数, has chain funcの時 From 632880d825bd6583648c44b534ed94b5c6d25925 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Tue, 10 Jul 2018 23:17:08 +0900 Subject: [PATCH 51/68] feat(test/single-delim): add test --- test/test_cxx17_string_view.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/test/test_cxx17_string_view.cpp b/test/test_cxx17_string_view.cpp index f7bdaa9..e587ea4 100644 --- a/test/test_cxx17_string_view.cpp +++ b/test/test_cxx17_string_view.cpp @@ -1,4 +1,4 @@ -#include "../include/string_split.hpp" +#include "../include/string_split.hpp" #ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW #include "../iutest/include/iutest.hpp" #include "constant.hpp" @@ -259,6 +259,20 @@ IUTEST_TYPED_TEST(StringViewSplit, ExtractByStlStrView) IUTEST_EXPECT_THROW(s | split(delim)[std::numeric_limits::max()], std::out_of_range); } #endif +IUTEST_TYPED_TEST(StringViewSplit, SplitBySingeChar) +{ + using char_type = TypeParam; + const std::basic_string_view s1 = constant::arikitari_na_world(); + const std::basic_string_view re1_1[] = { constant::arikitari(), constant::na(), constant::world() }; + const auto re1_2 = s1 | split(constant::space()); + IUTEST_ASSERT_TRUE(std::equal(std::begin(re1_1), std::end(re1_1), re1_2.begin(), re1_2.end())); + if constexpr(!std::is_same_v) { + const std::basic_string_view s2 = constant::arikitarina_sekai(); + const std::basic_string_view re2_1[] = { constant::arikitarina(), constant::sekai() }; + const auto re2_2 = s2 | split(constant::space()); + IUTEST_ASSERT_TRUE(std::equal(std::begin(re2_1), std::end(re2_1), re2_2.begin(), re2_2.end())); + } +} IUTEST_TYPED_TEST(StringViewSplit, SplitByCStr) { using char_type = TypeParam; From 7ee1c5fc2263cd390b6278794400a7b79ca2cd30 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Wed, 11 Jul 2018 19:56:38 +0900 Subject: [PATCH 52/68] fix(split_helper_conv_func): cut out FuncType check --- include/string_split.hpp | 148 ++++++++++++++++++++++++++++++--------- 1 file changed, 114 insertions(+), 34 deletions(-) diff --git a/include/string_split.hpp b/include/string_split.hpp index a7429c0..822964b 100644 --- a/include/string_split.hpp +++ b/include/string_split.hpp @@ -86,6 +86,88 @@ namespace detail { template struct is_stl_string : is_stl_string {}; template struct is_stl_string> : std::integral_constant>::value> {}; + + namespace detail { + template + struct is_reference_wrapper : std::false_type {}; + template + struct is_reference_wrapper> : std::true_type {}; + + template + struct invoke_impl { + template + static auto call(F&& f, Args&&... args) + -> decltype(std::forward(f)(std::forward(args)...)); + }; + + template + struct invoke_impl { + template::type, + class = typename std::enable_if::value>::type + > + static auto get(T&& t)->T&&; + + template::type, + class = typename std::enable_if::value>::type + > + static auto get(T&& t) -> decltype(t.get()); + + template::type, + class = typename std::enable_if::value>::type, + class = typename std::enable_if::value>::type + > + static auto get(T&& t) -> decltype(*std::forward(t)); + + template::value>::type + > + static auto call(MT1 B::*pmf, T&& t, Args&&... args) + -> decltype((invoke_impl::get(std::forward(t)).*pmf)(std::forward(args)...)); + + template + static auto call(MT B::*pmd, T&& t) + -> decltype(invoke_impl::get(std::forward(t)).*pmd); + }; + + template::type> + auto INVOKE(F&& f, Args&&... args) + -> decltype(invoke_impl::call(std::forward(f), std::forward(args)...)); + + } // namespace detail + + // Conforming C++14 implementation (is also a valid C++11 implementation): + namespace detail { + template + struct invoke_result { }; + template + struct invoke_result(), std::declval()...))), + F, Args...> { + using type = decltype(detail::INVOKE(std::declval(), std::declval()...)); + }; + } // namespace detail + + template + struct invoke_result : detail::invoke_result {}; + template< class F, class... ArgTypes> + using invoke_result_t = typename invoke_result::type; + + template struct conjunction : std::true_type { }; + template struct conjunction : B1 { }; + template + struct conjunction + : conditional_t, B1> {}; + + template struct disjunction : std::false_type { }; + template struct disjunction : B1 { }; + template + struct disjunction + : conditional_t> { }; + + template + using bool_constant = std::integral_constant; + + template + struct negation : bool_constant { }; #ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW // // is_stl_string_view @@ -192,30 +274,22 @@ namespace detail { template struct split_helper_conv_func { using char_type = CharType; - using result_type = decltype(std::declval()(std::declval>())); - static constexpr bool result_is_void = std::is_same::value; CharType delim; FuncType f; }; template struct split_helper_conv_func { using char_type = remove_cv_t>; - using result_type = decltype(std::declval()(std::declval>())); - static constexpr bool result_is_void = std::is_same::value; const char_type* delim; FuncType f; }; template struct split_helper_conv_func { using char_type = typename StlString::value_type; - using result_type = decltype(std::declval()(std::declval>())); - static constexpr bool result_is_void = std::is_same::value; b_str delim; FuncType f; }; #ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW template struct split_helper_conv_func { using char_type = typename StlStringView::value_type; - using result_type = std::invoke_result_t>; - static constexpr bool result_is_void = std::is_same::value; b_str delim; FuncType f; }; #endif @@ -426,7 +500,7 @@ namespace detail { template auto operator| (const b_str& str, const split_helper_conv_func& info) -> enable_if_t< - split_helper_conv_func::result_is_void, + std::is_void>>::value, void > { @@ -437,17 +511,14 @@ namespace detail { info.f(std::basic_string(str, current, str.size() - current)); } //区切り文字1文字, has chain convert funcの時 - template< - typename CharType, typename FuncType, - typename SplitHelperConvFunc = split_helper_conv_func - > + template auto operator| (const b_str& str, const split_helper_conv_func& info) -> enable_if_t< - !SplitHelperConvFunc::result_is_void, - vector + !std::is_void>>::value, + vector>> > { - vector re; + vector>> re; size_t current = 0; for (size_t found; (found = str.find_first_of(info.delim, current)) != b_str::npos; current = found + 1) { if (re.capacity() < re.size() + 1) re.reserve((std::numeric_limits::max() / 2 < re.size()) ? std::numeric_limits::max() : re.size() * 2); @@ -494,12 +565,14 @@ namespace detail { //区切り文字複数, has chain funcの時 template< typename CharType, typename DelimType, typename FuncType, - bool is_c_str, bool is_stl_string, - typename SplitHelperConvFunc = split_helper_conv_func + bool is_c_str, bool is_stl_string > auto operator| (const b_str& str, const split_helper_conv_func& info) -> enable_if_t< - (is_c_str || is_stl_string) && is_same::value && SplitHelperConvFunc::result_is_void, + (is_c_str || is_stl_string) && type_traits::conjunction< + is_same::char_type>, + std::is_void>> + >::value, void > { @@ -516,16 +589,18 @@ namespace detail { //区切り文字複数, has chain convert funcの時 template< typename CharType, typename DelimType, typename FuncType, - bool is_c_str, bool is_stl_string, - typename SplitHelperConvFunc = split_helper_conv_func + bool is_c_str, bool is_stl_string > auto operator| (const b_str& str, const split_helper_conv_func& info) -> enable_if_t< - (is_c_str || is_stl_string) && is_same::value && !SplitHelperConvFunc::result_is_void, - vector + (is_c_str || is_stl_string) && type_traits::conjunction< + is_same::char_type>, + type_traits::negation>>> + >::value, + vector>> > { - vector re; + vector>> re; size_t current = 0; for ( size_t found = str.find_first_of(info.delim, current); @@ -662,7 +737,7 @@ namespace detail { template auto operator| (b_str&& str, const split_helper_conv_func& info) -> enable_if_t< - split_helper_conv_func::result_is_void, + std::is_void>>::value, void > { @@ -680,11 +755,11 @@ namespace detail { > auto operator| (b_str&& str, const split_helper_conv_func& info) -> enable_if_t< - !SplitHelperConvFunc::result_is_void, - vector + !std::is_void>>::value, + vector>> > { - vector re; + vector>> re; size_t current = 0; for (size_t found; (found = str.find_first_of(info.delim, current)) != b_str::npos; current = found + 1) { if (re.capacity() < re.size() + 1) re.reserve((std::numeric_limits::max() / 2 < re.size()) ? std::numeric_limits::max() : re.size() * 2); @@ -711,12 +786,14 @@ namespace detail { //区切り文字複数, has chain funcの時 template< typename CharType, typename DelimType, typename FuncType, - bool is_c_str, bool is_stl_string, - typename SplitHelperConvFunc = split_helper_conv_func + bool is_c_str, bool is_stl_string > auto operator| (b_str&& str, const split_helper_conv_func& info) -> enable_if_t< - (is_c_str || is_stl_string) && is_same::value && SplitHelperConvFunc::result_is_void, + (is_c_str || is_stl_string) && type_traits::conjunction< + is_same::char_type>, + std::is_void>> + >::value, void > { @@ -739,11 +816,14 @@ namespace detail { > auto operator| (b_str&& str, const split_helper_conv_func& info) -> enable_if_t< - (is_c_str || is_stl_string) && is_same::value && !SplitHelperConvFunc::result_is_void, - vector + (is_c_str || is_stl_string) && type_traits::conjunction< + is_same::char_type>, + type_traits::negation>>> + >::value, + vector>> > { - vector re; + vector>> re; size_t current = 0; for ( size_t found = str.find_first_of(info.delim, current); From 0d8a97570956ba08a22a43546547951bcc1079ac Mon Sep 17 00:00:00 2001 From: yumetodo Date: Wed, 11 Jul 2018 21:27:28 +0900 Subject: [PATCH 53/68] feat(single-delim, chain): add impl --- include/string_split.hpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/include/string_split.hpp b/include/string_split.hpp index 822964b..539b1fc 100644 --- a/include/string_split.hpp +++ b/include/string_split.hpp @@ -497,6 +497,20 @@ namespace detail { return str.substr(pre, pos - pre); } //区切り文字1文字, has chain funcの時 +#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW + template< + typename StrType, typename CharType, typename FuncType, + enable_if_t< + type_traits::conjunction< + type_traits::contract_str_type, + std::is_void> + >::value, + std::nullptr_t + > = nullptr + > + void operator| (const StrType& str, const split_helper_conv_func& info) + { +#else template auto operator| (const b_str& str, const split_helper_conv_func& info) -> enable_if_t< @@ -504,11 +518,13 @@ namespace detail { void > { + using StrType = b_str; +#endif size_t current = 0; - for (size_t found; (found = str.find_first_of(info.delim, current)) != b_str::npos; current = found + 1) { - info.f(std::basic_string(str, current, found - current)); + for (size_t found; (found = str.find_first_of(info.delim, current)) != StrType::npos; current = found + 1) { + info.f(str.substr(current, found - current)); } - info.f(std::basic_string(str, current, str.size() - current)); + info.f(str.substr(current, str.size() - current)); } //区切り文字1文字, has chain convert funcの時 template From c844f3635fed570a5a5724c055e16ba1b8df3c84 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Wed, 11 Jul 2018 21:28:24 +0900 Subject: [PATCH 54/68] feat(test/single-delim, chain): add test --- test/test_cxx17_string_view.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/test_cxx17_string_view.cpp b/test/test_cxx17_string_view.cpp index e587ea4..4c86ed0 100644 --- a/test/test_cxx17_string_view.cpp +++ b/test/test_cxx17_string_view.cpp @@ -315,3 +315,23 @@ IUTEST_TYPED_TEST(StringViewSplit, SplitByStlStrView) IUTEST_ASSERT_TRUE(std::equal(std::begin(re2_1), std::end(re2_1), re2_2.begin(), re2_2.end())); } } +IUTEST_TYPED_TEST(StringViewSplit, chain_func_by_single_char) +{ + using char_type = TypeParam; + const std::basic_string s = constant::arikitari_na_world(); + const std::basic_string_view sv = s; + std::vector s_hash; + std::vector sv_hash; + s_hash.reserve(3); + sv_hash.reserve(3); + s | split(constant::space()) >> [&s_hash](const std::basic_string& part) { + s_hash.emplace_back(std::hash>()(part)); + }; + sv | split(constant::space()) >> [&sv_hash](const std::basic_string_view& part) { + sv_hash.emplace_back(std::hash>()(part)); + }; + //These hashes equal the hashes of corresponding std::basic_string classes: + //If S is one of the standard basic_string types, SV is the corresponding string view type, + //and s is an object of type S, then std::hash()(s) == std::hash()(SV(s)). + IUTEST_ASSERT_TRUE(std::equal(s_hash.begin(), s_hash.end(), sv_hash.begin(), sv_hash.end())); +} \ No newline at end of file From 65d71cee70967436b51c7d68a6c884d917442dfd Mon Sep 17 00:00:00 2001 From: yumetodo Date: Thu, 12 Jul 2018 20:12:26 +0900 Subject: [PATCH 55/68] feat(multi-delim, chain): add impl --- include/string_split.hpp | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/include/string_split.hpp b/include/string_split.hpp index 539b1fc..b99a4cc 100644 --- a/include/string_split.hpp +++ b/include/string_split.hpp @@ -290,7 +290,7 @@ namespace detail { template struct split_helper_conv_func { using char_type = typename StlStringView::value_type; - b_str delim; FuncType f; + b_str_view delim; FuncType f; }; #endif template @@ -335,7 +335,7 @@ namespace detail { b_str_view delim; split_helper_index operator[](size_t n) const noexcept { return{ std::move(delim), n }; } template::value, std::nullptr_t> = nullptr> - split_helper_conv_func operator >> (FuncType&& f) const { return{ std::move(delim), std::forward(f) }; } + split_helper_conv_func operator >> (FuncType&& f) const { return{ std::move(delim), std::forward(f) }; } split_helper_index operator>>(get_front) const noexcept { return{ std::move(delim), 0 }; } template::value, std::nullptr_t> = nullptr> split_helper_subroutine operator>> (Subroutine) const noexcept { return{ std::move(delim) }; } @@ -579,6 +579,21 @@ namespace detail { return re; } //区切り文字複数, has chain funcの時 +#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW + template< + typename StrType, typename DelimType, typename FuncType, + bool is_c_str, bool is_stl_string, + enable_if_t::char_type + >, + std::is_void> + >::value, std::nullptr_t> = nullptr + > + void operator| (const StrType& str, const split_helper_conv_func& info) + { +#else template< typename CharType, typename DelimType, typename FuncType, bool is_c_str, bool is_stl_string @@ -592,15 +607,17 @@ namespace detail { void > { + using StrType = b_str; +#endif size_t current = 0; for ( size_t found = str.find_first_of(info.delim, current); - current != b_str::npos && found != b_str::npos; + current != StrType::npos && found != StrType::npos; current = str.find_first_not_of(info.delim, found + 1), found = str.find_first_of(info.delim, current) ) { - info.f(std::basic_string(str, current, found - current)); + info.f(str.substr(current, found - current)); } - info.f(std::basic_string(str, current, str.size() - current)); + info.f(str.substr(current, str.size() - current)); } //区切り文字複数, has chain convert funcの時 template< From b877300a83f3b8e6e8e7e3be920b040d0d12b3ca Mon Sep 17 00:00:00 2001 From: yumetodo Date: Thu, 12 Jul 2018 20:12:51 +0900 Subject: [PATCH 56/68] feat(test/multi-delim, chain): add test --- test/test_cxx17_string_view.cpp | 60 +++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/test/test_cxx17_string_view.cpp b/test/test_cxx17_string_view.cpp index 4c86ed0..bf3c54c 100644 --- a/test/test_cxx17_string_view.cpp +++ b/test/test_cxx17_string_view.cpp @@ -334,4 +334,64 @@ IUTEST_TYPED_TEST(StringViewSplit, chain_func_by_single_char) //If S is one of the standard basic_string types, SV is the corresponding string view type, //and s is an object of type S, then std::hash()(s) == std::hash()(SV(s)). IUTEST_ASSERT_TRUE(std::equal(s_hash.begin(), s_hash.end(), sv_hash.begin(), sv_hash.end())); +} +IUTEST_TYPED_TEST(StringViewSplit, chain_func_by_single_c_str) +{ + using char_type = TypeParam; + const std::basic_string s = constant::arikitari_na_world_underscore(); + const std::basic_string_view sv = s; + std::vector s_hash; + std::vector sv_hash; + s_hash.reserve(3); + sv_hash.reserve(3); + s | split(constant::space_underscore()) >> [&s_hash](const std::basic_string& part) { + s_hash.emplace_back(std::hash>()(part)); + }; + sv | split(constant::space_underscore()) >> [&sv_hash](const std::basic_string_view& part) { + sv_hash.emplace_back(std::hash>()(part)); + }; + //These hashes equal the hashes of corresponding std::basic_string classes: + //If S is one of the standard basic_string types, SV is the corresponding string view type, + //and s is an object of type S, then std::hash()(s) == std::hash()(SV(s)). + IUTEST_ASSERT_TRUE(std::equal(s_hash.begin(), s_hash.end(), sv_hash.begin(), sv_hash.end())); +} +IUTEST_TYPED_TEST(StringViewSplit, chain_func_by_single_stl_str) +{ + using char_type = TypeParam; + const std::basic_string s = constant::arikitari_na_world_underscore(); + const std::basic_string_view sv = s; + std::vector s_hash; + std::vector sv_hash; + s_hash.reserve(3); + sv_hash.reserve(3); + s | split(std::basic_string(constant::space_underscore())) >> [&s_hash](const std::basic_string& part) { + s_hash.emplace_back(std::hash>()(part)); + }; + sv | split(std::basic_string(constant::space_underscore())) >> [&sv_hash](const std::basic_string_view& part) { + sv_hash.emplace_back(std::hash>()(part)); + }; + //These hashes equal the hashes of corresponding std::basic_string classes: + //If S is one of the standard basic_string types, SV is the corresponding string view type, + //and s is an object of type S, then std::hash()(s) == std::hash()(SV(s)). + IUTEST_ASSERT_TRUE(std::equal(s_hash.begin(), s_hash.end(), sv_hash.begin(), sv_hash.end())); +} +IUTEST_TYPED_TEST(StringViewSplit, chain_func_by_single_stl_str_view) +{ + using char_type = TypeParam; + const std::basic_string s = constant::arikitari_na_world_underscore(); + const std::basic_string_view sv = s; + std::vector s_hash; + std::vector sv_hash; + s_hash.reserve(3); + sv_hash.reserve(3); + s | split(std::basic_string_view(constant::space_underscore())) >> [&s_hash](const std::basic_string& part) { + s_hash.emplace_back(std::hash>()(part)); + }; + sv | split(std::basic_string_view(constant::space_underscore())) >> [&sv_hash](const std::basic_string_view& part) { + sv_hash.emplace_back(std::hash>()(part)); + }; + //These hashes equal the hashes of corresponding std::basic_string classes: + //If S is one of the standard basic_string types, SV is the corresponding string view type, + //and s is an object of type S, then std::hash()(s) == std::hash()(SV(s)). + IUTEST_ASSERT_TRUE(std::equal(s_hash.begin(), s_hash.end(), sv_hash.begin(), sv_hash.end())); } \ No newline at end of file From b8b3811d2848fe66ca7b45db88340cf8f419df4d Mon Sep 17 00:00:00 2001 From: yumetodo Date: Thu, 12 Jul 2018 21:29:30 +0900 Subject: [PATCH 57/68] feat(single-delim, chain_conv): add impl --- include/string_split.hpp | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/include/string_split.hpp b/include/string_split.hpp index b99a4cc..e4b81ba 100644 --- a/include/string_split.hpp +++ b/include/string_split.hpp @@ -527,6 +527,21 @@ namespace detail { info.f(str.substr(current, str.size() - current)); } //区切り文字1文字, has chain convert funcの時 +#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW + template< + typename StrType, typename CharType, typename FuncType, + enable_if_t< + type_traits::conjunction< + type_traits::contract_str_type, + type_traits::negation>> + >::value, + std::nullptr_t + > = nullptr + > + auto operator| (const StrType& str, const split_helper_conv_func& info) + -> vector> + { +#else template auto operator| (const b_str& str, const split_helper_conv_func& info) -> enable_if_t< @@ -534,13 +549,15 @@ namespace detail { vector>> > { - vector>> re; + using StrType = b_str; +#endif + vector> re; size_t current = 0; - for (size_t found; (found = str.find_first_of(info.delim, current)) != b_str::npos; current = found + 1) { + for (size_t found; (found = str.find_first_of(info.delim, current)) != StrType::npos; current = found + 1) { if (re.capacity() < re.size() + 1) re.reserve((std::numeric_limits::max() / 2 < re.size()) ? std::numeric_limits::max() : re.size() * 2); - re.push_back(info.f(std::basic_string(str, current, found - current))); + re.emplace_back(info.f(str.substr(current, found - current))); } - re.push_back(info.f(std::basic_string(str, current, str.size() - current))); + re.emplace_back(info.f(str.substr(current, str.size() - current))); return re; } #ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW From 5f4557ad63c07fed5ffb1a830030c53ed11ce8ae Mon Sep 17 00:00:00 2001 From: yumetodo Date: Thu, 12 Jul 2018 21:30:20 +0900 Subject: [PATCH 58/68] feat(test/single-delim, chain_conv): add test --- test/test_cxx17_string_view.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/test/test_cxx17_string_view.cpp b/test/test_cxx17_string_view.cpp index bf3c54c..0afa4ec 100644 --- a/test/test_cxx17_string_view.cpp +++ b/test/test_cxx17_string_view.cpp @@ -394,4 +394,20 @@ IUTEST_TYPED_TEST(StringViewSplit, chain_func_by_single_stl_str_view) //If S is one of the standard basic_string types, SV is the corresponding string view type, //and s is an object of type S, then std::hash()(s) == std::hash()(SV(s)). IUTEST_ASSERT_TRUE(std::equal(s_hash.begin(), s_hash.end(), sv_hash.begin(), sv_hash.end())); -} \ No newline at end of file +} +IUTEST_TYPED_TEST(StringViewSplit, chain_conv_func_by_single_char) +{ + using char_type = TypeParam; + const std::basic_string s = constant::arikitari_na_world(); + const std::basic_string_view sv = s; + auto s_hash = s | split(constant::space()) >> [](const std::basic_string& part) { + return std::hash>()(part); + }; + auto sv_hash = sv | split(constant::space()) >> [](const std::basic_string_view& part) { + return std::hash>()(part); + }; + //These hashes equal the hashes of corresponding std::basic_string classes: + //If S is one of the standard basic_string types, SV is the corresponding string view type, + //and s is an object of type S, then std::hash()(s) == std::hash()(SV(s)). + IUTEST_ASSERT_TRUE(std::equal(s_hash.begin(), s_hash.end(), sv_hash.begin(), sv_hash.end())); +} From 4ac8bd9059655bd549c7a8bd49b193f307ebc17b Mon Sep 17 00:00:00 2001 From: yumetodo Date: Sat, 14 Jul 2018 16:51:55 +0900 Subject: [PATCH 59/68] feat: add usefull type traits and contract --- include/string_split.hpp | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/include/string_split.hpp b/include/string_split.hpp index e4b81ba..1b1ed69 100644 --- a/include/string_split.hpp +++ b/include/string_split.hpp @@ -1,4 +1,4 @@ -/*============================================================================= +/*============================================================================= Copyright (C) 2016-2018 yumetodo Distributed under the Boost Software License, Version 1.0. @@ -49,6 +49,7 @@ namespace detail { #endif using std::is_same; using std::size_t; + using std::is_void; template using enable_if_t = typename std::enable_if::type; template @@ -192,11 +193,15 @@ namespace detail { // template struct contract_str_type : std::conjunction< type_traits::is_stl_string_or_stl_string_view, - std::is_same + is_same > {}; template constexpr bool contract_str_type_v = contract_str_type::value; #endif } +#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW + using std::conjunction_v; +#endif + using type_traits::invoke_result_t; struct subroutine_base {}; template struct is_subroutine : std::is_base_of {}; struct get_front : subroutine_base {}; @@ -340,7 +345,32 @@ namespace detail { template::value, std::nullptr_t> = nullptr> split_helper_subroutine operator>> (Subroutine) const noexcept { return{ std::move(delim) }; } }; + namespace type_traits { + // + //contract_str_type_and_delim_type_without_single_char + // + //is_c_str: true && is_stl_string: true => impossible!!! + //is_c_str: true && is_stl_string: false => const T* + //is_c_str: false && is_stl_string: true => std::basic_string + //is_c_str: false && is_stl_string: false => std::basic_string_view + template + struct contract_str_type_and_delim_type_without_single_char : conjunction< + contract_str_type::char_type>, + bool_constant + > + {}; + template + constexpr bool contract_str_type_and_delim_type_without_single_char_v = contract_str_type_and_delim_type_without_single_char::value; + } #endif + namespace type_traits { + template + struct contract_delim_type_without_single_char : conjunction< + is_same::char_type>, + bool_constant<(is_c_str || is_stl_string)> + > + {}; + } //back()の時 #ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW template< From 7e24c4270c81344eafe6574b21c3d5f12147252c Mon Sep 17 00:00:00 2001 From: yumetodo Date: Sat, 14 Jul 2018 16:57:09 +0900 Subject: [PATCH 60/68] feat(multi-delim, chain_conv): add impl --- include/string_split.hpp | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/include/string_split.hpp b/include/string_split.hpp index 1b1ed69..dbf7329 100644 --- a/include/string_split.hpp +++ b/include/string_split.hpp @@ -667,30 +667,45 @@ namespace detail { info.f(str.substr(current, str.size() - current)); } //区切り文字複数, has chain convert funcの時 +#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW + template< + typename StrType, typename DelimType, typename FuncType, + bool is_c_str, bool is_stl_string, + enable_if_t, + type_traits::negation>> + >, std::nullptr_t> = nullptr + > + auto operator| (const StrType& str, const split_helper_conv_func& info) + -> vector> + { +#else template< typename CharType, typename DelimType, typename FuncType, bool is_c_str, bool is_stl_string > auto operator| (const b_str& str, const split_helper_conv_func& info) -> enable_if_t< - (is_c_str || is_stl_string) && type_traits::conjunction< - is_same::char_type>, - type_traits::negation>>> + type_traits::conjunction< + type_traits::contract_delim_type_without_single_char, + type_traits::negation>>> >::value, - vector>> + vector>> > { - vector>> re; + using StrType = b_str; +#endif + vector> re; size_t current = 0; for ( size_t found = str.find_first_of(info.delim, current); - current != b_str::npos && found != b_str::npos; + current != StrType::npos && found != StrType::npos; current = str.find_first_not_of(info.delim, found + 1), found = str.find_first_of(info.delim, current) ) { if (re.capacity() < re.size() + 1) re.reserve((std::numeric_limits::max() / 2 < re.size()) ? std::numeric_limits::max() : re.size() * 2); - re.push_back(info.f(std::basic_string(str, current, found - current))); + re.emplace_back(info.f(str.substr(current, found - current))); } - re.push_back(info.f(std::basic_string(str, current, str.size() - current))); + re.emplace_back(info.f(str.substr(current, str.size() - current))); return re; } //区切り文字複数の時 From 7df37795faf55e868aa4ed9039bc5a0c47cd0f59 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Sat, 14 Jul 2018 17:00:10 +0900 Subject: [PATCH 61/68] fix: use usefull type traits and contract --- include/string_split.hpp | 97 ++++++++++++++++------------------------ 1 file changed, 39 insertions(+), 58 deletions(-) diff --git a/include/string_split.hpp b/include/string_split.hpp index dbf7329..c347dde 100644 --- a/include/string_split.hpp +++ b/include/string_split.hpp @@ -1,4 +1,4 @@ -/*============================================================================= +/*============================================================================= Copyright (C) 2016-2018 yumetodo Distributed under the Boost Software License, Version 1.0. @@ -496,10 +496,7 @@ namespace detail { #ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW template< typename StrType, typename DelimType, bool is_c_str, bool is_stl_string, - enable_if_t::char_type - >, std::nullptr_t> = nullptr + enable_if_t, std::nullptr_t> = nullptr > auto operator| (const StrType& str, const split_helper_index& info) -> StrType { @@ -507,11 +504,7 @@ namespace detail { template auto operator| (const b_str& str, const split_helper_index& info) -> enable_if_t< - //is_c_str: true && is_stl_string: true => impossible!!! - //is_c_str: true && is_stl_string: false => const T* - //is_c_str: false && is_stl_string: true => std::basic_string - //is_c_str: false && is_stl_string: false => std::basic_string_view - !(is_c_str && is_stl_string) && is_same::char_type>::value, + type_traits::contract_delim_type_without_single_char::value, b_str > { @@ -530,13 +523,10 @@ namespace detail { #ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW template< typename StrType, typename CharType, typename FuncType, - enable_if_t< - type_traits::conjunction< - type_traits::contract_str_type, - std::is_void> - >::value, - std::nullptr_t - > = nullptr + enable_if_t, + is_void> + >, std::nullptr_t> = nullptr > void operator| (const StrType& str, const split_helper_conv_func& info) { @@ -544,7 +534,7 @@ namespace detail { template auto operator| (const b_str& str, const split_helper_conv_func& info) -> enable_if_t< - std::is_void>>::value, + is_void>>::value, void > { @@ -560,28 +550,25 @@ namespace detail { #ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW template< typename StrType, typename CharType, typename FuncType, - enable_if_t< - type_traits::conjunction< - type_traits::contract_str_type, - type_traits::negation>> - >::value, - std::nullptr_t - > = nullptr + enable_if_t, + type_traits::negation>> + >, std::nullptr_t> = nullptr > auto operator| (const StrType& str, const split_helper_conv_func& info) - -> vector> + -> vector> { #else template auto operator| (const b_str& str, const split_helper_conv_func& info) -> enable_if_t< - !std::is_void>>::value, - vector>> + !is_void>>::value, + vector>> > { using StrType = b_str; #endif - vector> re; + vector> re; size_t current = 0; for (size_t found; (found = str.find_first_of(info.delim, current)) != StrType::npos; current = found + 1) { if (re.capacity() < re.size() + 1) re.reserve((std::numeric_limits::max() / 2 < re.size()) ? std::numeric_limits::max() : re.size() * 2); @@ -630,13 +617,10 @@ namespace detail { template< typename StrType, typename DelimType, typename FuncType, bool is_c_str, bool is_stl_string, - enable_if_t::char_type - >, - std::is_void> - >::value, std::nullptr_t> = nullptr + enable_if_t, + is_void> + >, std::nullptr_t> = nullptr > void operator| (const StrType& str, const split_helper_conv_func& info) { @@ -647,9 +631,9 @@ namespace detail { > auto operator| (const b_str& str, const split_helper_conv_func& info) -> enable_if_t< - (is_c_str || is_stl_string) && type_traits::conjunction< - is_same::char_type>, - std::is_void>> + type_traits::conjunction< + type_traits::contract_delim_type_without_single_char + is_void>> >::value, void > @@ -712,10 +696,7 @@ namespace detail { #ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW template< typename StrType, typename DelimType, bool is_c_str, bool is_stl_string, - enable_if_t::char_type - >, std::nullptr_t> = nullptr + enable_if_t, std::nullptr_t> = nullptr > auto operator| (const StrType& str, const split_helper& info) -> vector { @@ -723,7 +704,7 @@ namespace detail { template auto operator| (const b_str& str, const split_helper& info) -> enable_if_t< - (is_c_str || is_stl_string) && is_same::char_type>::value, + type_traits::contract_delim_type_without_single_char::value, vector> > { @@ -813,7 +794,7 @@ namespace detail { template auto operator| (b_str&& str, const split_helper_index& info) -> enable_if_t< - (is_c_str || is_stl_string) && is_same::char_type>::value, + type_traits::contract_delim_type_without_single_char::value, b_str > { @@ -832,7 +813,7 @@ namespace detail { template auto operator| (b_str&& str, const split_helper_conv_func& info) -> enable_if_t< - std::is_void>>::value, + is_void>>::value, void > { @@ -850,11 +831,11 @@ namespace detail { > auto operator| (b_str&& str, const split_helper_conv_func& info) -> enable_if_t< - !std::is_void>>::value, - vector>> + !is_void>>::value, + vector>> > { - vector>> re; + vector>> re; size_t current = 0; for (size_t found; (found = str.find_first_of(info.delim, current)) != b_str::npos; current = found + 1) { if (re.capacity() < re.size() + 1) re.reserve((std::numeric_limits::max() / 2 < re.size()) ? std::numeric_limits::max() : re.size() * 2); @@ -885,9 +866,9 @@ namespace detail { > auto operator| (b_str&& str, const split_helper_conv_func& info) -> enable_if_t< - (is_c_str || is_stl_string) && type_traits::conjunction< - is_same::char_type>, - std::is_void>> + type_traits::conjunction< + type_traits::contract_delim_type_without_single_char, + is_void>> >::value, void > @@ -911,14 +892,14 @@ namespace detail { > auto operator| (b_str&& str, const split_helper_conv_func& info) -> enable_if_t< - (is_c_str || is_stl_string) && type_traits::conjunction< - is_same::char_type>, - type_traits::negation>>> + type_traits::conjunction< + type_traits::contract_delim_type_without_single_char, + type_traits::negation>>> >::value, - vector>> + vector>> > { - vector>> re; + vector>> re; size_t current = 0; for ( size_t found = str.find_first_of(info.delim, current); @@ -936,7 +917,7 @@ namespace detail { template auto operator| (b_str&& str, const split_helper& info) -> enable_if_t< - (is_c_str || is_stl_string) && is_same::char_type>::value, + type_traits::contract_delim_type_without_single_char::value, vector> > { From 03ba86c0db7d3ce6c3355dd63bd3c43c38ad31d9 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Sat, 14 Jul 2018 17:00:57 +0900 Subject: [PATCH 62/68] chore(test): s/single_c_str/c_str/ --- test/test_cxx17_string_view.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_cxx17_string_view.cpp b/test/test_cxx17_string_view.cpp index 0afa4ec..2ad4681 100644 --- a/test/test_cxx17_string_view.cpp +++ b/test/test_cxx17_string_view.cpp @@ -1,4 +1,4 @@ -#include "../include/string_split.hpp" +#include "../include/string_split.hpp" #ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW #include "../iutest/include/iutest.hpp" #include "constant.hpp" @@ -335,7 +335,7 @@ IUTEST_TYPED_TEST(StringViewSplit, chain_func_by_single_char) //and s is an object of type S, then std::hash()(s) == std::hash()(SV(s)). IUTEST_ASSERT_TRUE(std::equal(s_hash.begin(), s_hash.end(), sv_hash.begin(), sv_hash.end())); } -IUTEST_TYPED_TEST(StringViewSplit, chain_func_by_single_c_str) +IUTEST_TYPED_TEST(StringViewSplit, chain_func_by_c_str) { using char_type = TypeParam; const std::basic_string s = constant::arikitari_na_world_underscore(); From 9ca848d69aab219a138472e03ff337dba804bf8f Mon Sep 17 00:00:00 2001 From: yumetodo Date: Sat, 14 Jul 2018 17:01:44 +0900 Subject: [PATCH 63/68] feat(test/multi-delim, chain_conv): add test --- test/test_cxx17_string_view.cpp | 50 ++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/test/test_cxx17_string_view.cpp b/test/test_cxx17_string_view.cpp index 2ad4681..c7880ef 100644 --- a/test/test_cxx17_string_view.cpp +++ b/test/test_cxx17_string_view.cpp @@ -1,4 +1,4 @@ -#include "../include/string_split.hpp" +#include "../include/string_split.hpp" #ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW #include "../iutest/include/iutest.hpp" #include "constant.hpp" @@ -411,3 +411,51 @@ IUTEST_TYPED_TEST(StringViewSplit, chain_conv_func_by_single_char) //and s is an object of type S, then std::hash()(s) == std::hash()(SV(s)). IUTEST_ASSERT_TRUE(std::equal(s_hash.begin(), s_hash.end(), sv_hash.begin(), sv_hash.end())); } +IUTEST_TYPED_TEST(StringViewSplit, chain_conv_func_by_c_str) +{ + using char_type = TypeParam; + const std::basic_string s = constant::arikitari_na_world_underscore(); + const std::basic_string_view sv = s; + auto s_hash = s | split(constant::space_underscore()) >> [](const std::basic_string& part) { + return std::hash>()(part); + }; + auto sv_hash = sv | split(constant::space_underscore()) >> [](const std::basic_string_view& part) { + return std::hash>()(part); + }; + //These hashes equal the hashes of corresponding std::basic_string classes: + //If S is one of the standard basic_string types, SV is the corresponding string view type, + //and s is an object of type S, then std::hash()(s) == std::hash()(SV(s)). + IUTEST_ASSERT_TRUE(std::equal(s_hash.begin(), s_hash.end(), sv_hash.begin(), sv_hash.end())); +} +IUTEST_TYPED_TEST(StringViewSplit, chain_conv_func_by_stl_str) +{ + using char_type = TypeParam; + const std::basic_string s = constant::arikitari_na_world_underscore(); + const std::basic_string_view sv = s; + auto s_hash = s | split(std::basic_string(constant::space_underscore())) >> [](const std::basic_string& part) { + return std::hash>()(part); + }; + auto sv_hash = sv | split(std::basic_string(constant::space_underscore())) >> [](const std::basic_string_view& part) { + return std::hash>()(part); + }; + //These hashes equal the hashes of corresponding std::basic_string classes: + //If S is one of the standard basic_string types, SV is the corresponding string view type, + //and s is an object of type S, then std::hash()(s) == std::hash()(SV(s)). + IUTEST_ASSERT_TRUE(std::equal(s_hash.begin(), s_hash.end(), sv_hash.begin(), sv_hash.end())); +} +IUTEST_TYPED_TEST(StringViewSplit, chain_conv_func_by_stl_str_view) +{ + using char_type = TypeParam; + const std::basic_string s = constant::arikitari_na_world_underscore(); + const std::basic_string_view sv = s; + auto s_hash = s | split(std::basic_string_view(constant::space_underscore())) >> [](const std::basic_string& part) { + return std::hash>()(part); + }; + auto sv_hash = sv | split(std::basic_string_view(constant::space_underscore())) >> [](const std::basic_string_view& part) { + return std::hash>()(part); + }; + //These hashes equal the hashes of corresponding std::basic_string classes: + //If S is one of the standard basic_string types, SV is the corresponding string view type, + //and s is an object of type S, then std::hash()(s) == std::hash()(SV(s)). + IUTEST_ASSERT_TRUE(std::equal(s_hash.begin(), s_hash.end(), sv_hash.begin(), sv_hash.end())); +} From b641f86d91fe9a0a8c0eaf97baa2568ddd689e9a Mon Sep 17 00:00:00 2001 From: yumetodo Date: Sat, 14 Jul 2018 17:18:04 +0900 Subject: [PATCH 64/68] fix: devide test code for fast 2ndary build --- test/CMakeLists.txt | 2 + test/test.cpp | 801 +------------------------------- test/test_cxx17_string_view.cpp | 8 +- test/test_lvalue.cpp | 456 ++++++++++++++++++ test/test_rvalue.cpp | 388 ++++++++++++++++ 5 files changed, 854 insertions(+), 801 deletions(-) create mode 100644 test/test_lvalue.cpp create mode 100644 test/test_rvalue.cpp diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index ed5e2db..7a13e6a 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -32,6 +32,8 @@ project(basic_test) # set(basic_test_src "./test.cpp" + "./test_lvalue.cpp" + "./test_rvalue.cpp" ) if(CMAKE_CXX_STANDARD GREATER_EQUAL 17) message("C++17 sources enabled") diff --git a/test/test.cpp b/test/test.cpp index 07f7a48..79dd108 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -6,807 +6,8 @@ =============================================================================*/ #include "../include/string_split.hpp" #include "../iutest/include/iutest.hpp" -#include "constant.hpp" -#include -#include -#include -template -struct StringSplitLvalue : public ::iutest::Test {}; -IUTEST_TYPED_TEST_CASE(StringSplitLvalue, ::iutest::Types); -IUTEST_TYPED_TEST(StringSplitLvalue, chain_front_by_singe_char) -{ - using char_type = TypeParam; - const std::basic_string s = constant::cpp_basic_istream(); - const auto re = s | split(constant::space()) >> front(); - IUTEST_ASSERT_EQ(constant::cpp_basic_istream_part(), re); -} -IUTEST_TYPED_TEST(StringSplitLvalue, chain_front_by_c_str) -{ - using char_type = TypeParam; - const std::basic_string s = constant::arikitari_na_world_underscore(); - constexpr auto delim = constant::space_underscore(); - IUTEST_ASSERT_EQ(constant::arikitari(), s | split(delim) >> front()); -} -IUTEST_TYPED_TEST(StringSplitLvalue, chain_front_by_stl_str) -{ - using char_type = TypeParam; - const std::basic_string s = constant::arikitari_na_world_underscore(); - const std::basic_string delim = constant::space_underscore(); - IUTEST_ASSERT_EQ(constant::arikitari(), s | split(delim) >> front()); -} -#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW -IUTEST_TYPED_TEST(StringSplitLvalue, chain_front_by_stl_str_view) -{ - using char_type = TypeParam; - const std::basic_string s = constant::arikitari_na_world_underscore(); - const std::basic_string_view delim = constant::space_underscore(); - IUTEST_ASSERT_EQ(constant::arikitari(), s | split(delim) >> front()); -} -#endif -IUTEST_TYPED_TEST(StringSplitLvalue, chain_back_by_singe_char) -{ - using char_type = TypeParam; - const std::basic_string s = constant::arikitari_na_world(); - const auto re = s | split(constant::space()) >> back(); - IUTEST_ASSERT_EQ(constant::world(), re); -} -IUTEST_TYPED_TEST(StringSplitLvalue, chain_back_by_c_str) -{ - using char_type = TypeParam; - const std::basic_string s = constant::arikitari_na_world_underscore(); - constexpr auto delim = constant::space_underscore(); - IUTEST_ASSERT_EQ(constant::world(), s | split(delim) >> back()); -} -IUTEST_TYPED_TEST(StringSplitLvalue, chain_back_by_stl_str) -{ - using char_type = TypeParam; - const std::basic_string s = constant::arikitari_na_world_underscore(); - const std::basic_string delim = constant::space_underscore(); - IUTEST_ASSERT_EQ(constant::world(), s | split(delim) >> back()); -} -#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW -IUTEST_TYPED_TEST(StringSplitLvalue, chain_back_by_stl_str_view) -{ - using char_type = TypeParam; - const std::basic_string s = constant::arikitari_na_world_underscore(); - const std::basic_string_view delim = constant::space_underscore(); - IUTEST_ASSERT_EQ(constant::world(), s | split(delim) >> back()); -} -#endif -IUTEST_TYPED_TEST(StringSplitLvalue, chain_at_first_front) -{ - using char_type = TypeParam; - const std::basic_string s = constant::cpp_type_data2(); - const auto re = s | split(constant::space()) >> at_first().front(); - IUTEST_ASSERT_EQ(constant::cpp_dxle_sound_c(), re); -} -IUTEST_TYPED_TEST(StringSplitLvalue, chain_at_first_back_by_single_char) -{ - using char_type = TypeParam; - const std::basic_string s = constant::cpp_type_data2(); - const auto re = s | split(constant::space()) >> at_first().back(); - IUTEST_ASSERT_EQ(constant::cpp_LoadSoundMem(), re); -} -IUTEST_TYPED_TEST(StringSplitLvalue, chain_at_first_back_by_c_str) -{ - using char_type = TypeParam; - const std::basic_string s = constant::arikitari_na_world_underscore(); - const auto re = s | split(constant::space_underscore()) >> at_first().back(); - IUTEST_ASSERT_EQ(constant::na_world(), re); -} -IUTEST_TYPED_TEST(StringSplitLvalue, chain_at_first_back_by_stl_str) -{ - using char_type = TypeParam; - const std::basic_string s = constant::arikitari_na_world_underscore(); - const auto re = s | split(std::basic_string(constant::space_underscore())) >> at_first().back(); - IUTEST_ASSERT_EQ(constant::na_world(), re); -} -#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW -IUTEST_TYPED_TEST(StringSplitLvalue, chain_at_first_back_by_stl_str_view) -{ - using char_type = TypeParam; - const std::basic_string s = constant::arikitari_na_world_underscore(); - const auto re = s | split(std::basic_string_view(constant::space_underscore())) >> at_first().back(); - IUTEST_ASSERT_EQ(constant::na_world(), re); -} -#endif -IUTEST_TYPED_TEST(StringSplitLvalue, chain_at_first_by_single_char) -{ - using char_type = TypeParam; - const std::basic_string s = constant::cpp_type_data2(); - const auto re = s | split(constant::space()) >> at_first(); - IUTEST_ASSERT(2u == re.size()); - IUTEST_ASSERT_EQ(constant::cpp_dxle_sound_c(), re[0]); - IUTEST_ASSERT_EQ(constant::cpp_LoadSoundMem(), re[1]); -} -IUTEST_TYPED_TEST(StringSplitLvalue, chain_at_first_by_c_str) -{ - using char_type = TypeParam; - const std::basic_string s = constant::arikitari_na_world_underscore(); - const auto re = s | split(constant::space_underscore()) >> at_first(); - IUTEST_ASSERT(2u == re.size()); - IUTEST_ASSERT_EQ(constant::arikitari(), re[0]); - IUTEST_ASSERT_EQ(constant::na_world(), re[1]); -} -IUTEST_TYPED_TEST(StringSplitLvalue, chain_at_first_by_stl_str) -{ - using char_type = TypeParam; - const std::basic_string s = constant::arikitari_na_world_underscore(); - const auto re = s | split(std::basic_string(constant::space_underscore())) >> at_first(); - IUTEST_ASSERT(2u == re.size()); - IUTEST_ASSERT_EQ(constant::arikitari(), re[0]); - IUTEST_ASSERT_EQ(constant::na_world(), re[1]); -} -#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW -IUTEST_TYPED_TEST(StringSplitLvalue, chain_at_first_by_stl_str_view) -{ - using char_type = TypeParam; - const std::basic_string s = constant::arikitari_na_world_underscore(); - const auto re = s | split(std::basic_string_view(constant::space_underscore())) >> at_first(); - IUTEST_ASSERT(2u == re.size()); - IUTEST_ASSERT_EQ(constant::arikitari(), re[0]); - IUTEST_ASSERT_EQ(constant::na_world(), re[1]); -} -#endif -IUTEST_TYPED_TEST(StringSplitLvalue, chain_at_last_front_by_single_char) -{ - using char_type = TypeParam; - const std::basic_string s = constant::cpp_type_data1(); - const auto re = s | split(constant::colon()) >> at_last().front(); - IUTEST_ASSERT_EQ(constant::cpp_basic_istream(), re); -} -IUTEST_TYPED_TEST(StringSplitLvalue, chain_at_last_front_by_c_str) -{ - using char_type = TypeParam; - const std::basic_string s = constant::arikitari_na_world_underscore(); - const auto re = s | split(constant::space_underscore()) >> at_last().front(); - IUTEST_ASSERT_EQ(constant::arikitari_na(), re); -} -IUTEST_TYPED_TEST(StringSplitLvalue, chain_at_last_front_by_stl_str) -{ - using char_type = TypeParam; - const std::basic_string s = constant::arikitari_na_world_underscore(); - const auto re = s | split(std::basic_string(constant::space_underscore())) >> at_last().front(); - IUTEST_ASSERT_EQ(constant::arikitari_na(), re); -} -#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW -IUTEST_TYPED_TEST(StringSplitLvalue, chain_at_last_front_by_stl_str_view) -{ - using char_type = TypeParam; - const std::basic_string s = constant::arikitari_na_world_underscore(); - const auto re = s | split(std::basic_string_view(constant::space_underscore())) >> at_last().front(); - IUTEST_ASSERT_EQ(constant::arikitari_na(), re); -} -#endif -IUTEST_TYPED_TEST(StringSplitLvalue, chain_at_last_back) -{ - using char_type = TypeParam; - const std::basic_string s = constant::cpp_type_data1(); - const auto re = s | split(constant::colon()) >> at_last().back(); - IUTEST_ASSERT_EQ(constant::ignore(), re); -} -IUTEST_TYPED_TEST(StringSplitLvalue, chain_at_last_by_single_char) -{ - using char_type = TypeParam; - const std::basic_string s = constant::cpp_type_data1(); - const auto re = s | split(constant::colon()) >> at_last(); - IUTEST_ASSERT(2u == re.size()); - IUTEST_ASSERT_EQ(constant::cpp_basic_istream(), re[0]); - IUTEST_ASSERT_EQ(constant::ignore(), re[1]); -} -IUTEST_TYPED_TEST(StringSplitLvalue, chain_at_last_by_c_str) -{ - using char_type = TypeParam; - const std::basic_string s = constant::arikitari_na_world_underscore(); - const auto re = s | split(constant::space_underscore()) >> at_last(); - IUTEST_ASSERT(2u == re.size()); - IUTEST_ASSERT_EQ(constant::arikitari_na(), re[0]); - IUTEST_ASSERT_EQ(constant::world(), re[1]); -} -IUTEST_TYPED_TEST(StringSplitLvalue, chain_at_last_by_stl_str) -{ - using char_type = TypeParam; - const std::basic_string s = constant::arikitari_na_world_underscore(); - const auto re = s | split(std::basic_string(constant::space_underscore())) >> at_last(); - IUTEST_ASSERT(2u == re.size()); - IUTEST_ASSERT_EQ(constant::arikitari_na(), re[0]); - IUTEST_ASSERT_EQ(constant::world(), re[1]); -} -#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW -IUTEST_TYPED_TEST(StringSplitLvalue, chain_at_last_by_stl_str_view) -{ - using char_type = TypeParam; - const std::basic_string s = constant::arikitari_na_world_underscore(); - const auto re = s | split(std::basic_string_view(constant::space_underscore())) >> at_last(); - IUTEST_ASSERT(2u == re.size()); - IUTEST_ASSERT_EQ(constant::arikitari_na(), re[0]); - IUTEST_ASSERT_EQ(constant::world(), re[1]); -} -#endif -IUTEST_TYPED_TEST(StringSplitLvalue, ExtractBySingeChar) -{ - using char_type = TypeParam; - constexpr char_type space = constant::space(); - const std::basic_string s = constant::arikitari_na_world(); - IUTEST_ASSERT_EQ(constant::arikitari(), s | split(space)[0]); - IUTEST_ASSERT_EQ(constant::na(), s | split(space)[1]); - IUTEST_ASSERT_EQ(constant::world(), s | split(space)[2]); - IUTEST_EXPECT_THROW(s | split(space)[3], std::out_of_range); - IUTEST_EXPECT_THROW(s | split(space)[5], std::out_of_range); - IUTEST_EXPECT_THROW(s | split(space)[3250], std::out_of_range); - IUTEST_EXPECT_THROW(s | split(space)[std::numeric_limits::max()], std::out_of_range); -} -IUTEST_TYPED_TEST(StringSplitLvalue, ExtractByCStr) -{ - using char_type = TypeParam; - const std::basic_string s = constant::arikitari_na_world_underscore(); - constexpr auto delim = constant::space_underscore(); - IUTEST_ASSERT_EQ(constant::arikitari(), s | split(delim)[0]); - IUTEST_ASSERT_EQ(constant::na(), s | split(delim)[1]); - IUTEST_ASSERT_EQ(constant::world(), s | split(delim)[2]); - IUTEST_EXPECT_THROW(s | split(delim)[3], std::out_of_range); - IUTEST_EXPECT_THROW(s | split(delim)[5], std::out_of_range); - IUTEST_EXPECT_THROW(s | split(delim)[3250], std::out_of_range); - IUTEST_EXPECT_THROW(s | split(delim)[std::numeric_limits::max()], std::out_of_range); -} -IUTEST_TYPED_TEST(StringSplitLvalue, ExtractByStlStr) -{ - using char_type = TypeParam; - const std::basic_string s = constant::arikitari_na_world_underscore(); - const std::basic_string delim = constant::space_underscore(); - IUTEST_ASSERT_EQ(constant::arikitari(), s | split(delim)[0]); - IUTEST_ASSERT_EQ(constant::na(), s | split(delim)[1]); - IUTEST_ASSERT_EQ(constant::world(), s | split(delim)[2]); - IUTEST_EXPECT_THROW(s | split(delim)[3], std::out_of_range); - IUTEST_EXPECT_THROW(s | split(delim)[5], std::out_of_range); - IUTEST_EXPECT_THROW(s | split(delim)[3250], std::out_of_range); - IUTEST_EXPECT_THROW(s | split(delim)[std::numeric_limits::max()], std::out_of_range); -} -#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW -IUTEST_TYPED_TEST(StringSplitLvalue, ExtractByStlStrView) -{ - using char_type = TypeParam; - const std::basic_string s = constant::arikitari_na_world_underscore(); - const std::basic_string_view delim = constant::space_underscore(); - IUTEST_ASSERT_EQ(constant::arikitari(), s | split(delim)[0]); - IUTEST_ASSERT_EQ(constant::na(), s | split(delim)[1]); - IUTEST_ASSERT_EQ(constant::world(), s | split(delim)[2]); - IUTEST_EXPECT_THROW(s | split(delim)[3], std::out_of_range); - IUTEST_EXPECT_THROW(s | split(delim)[5], std::out_of_range); - IUTEST_EXPECT_THROW(s | split(delim)[3250], std::out_of_range); - IUTEST_EXPECT_THROW(s | split(delim)[std::numeric_limits::max()], std::out_of_range); -} -#endif -namespace StringSplitLvalue_SplitBySingeChar { - template::value, std::nullptr_t> = nullptr> - void without_char() - { - using char_type = CharType; - const std::basic_string s2 = constant::arikitarina_sekai(); - const std::basic_string re2_1[] = { constant::arikitarina(), constant::sekai() }; - const auto re2_2 = s2 | split(constant::space()); - IUTEST_ASSERT_TRUE(std::equal(std::begin(re2_1), std::end(re2_1), re2_2.begin(), re2_2.end())); - } - template::value, std::nullptr_t> = nullptr> - void without_char(){} -} -IUTEST_TYPED_TEST(StringSplitLvalue, SplitBySingeChar) -{ - using char_type = TypeParam; - const std::basic_string s1 = constant::arikitari_na_world(); - const std::basic_string re1_1[] = { constant::arikitari(), constant::na(), constant::world() }; - const auto re1_2 = s1 | split(constant::space()); - IUTEST_ASSERT_TRUE(std::equal(std::begin(re1_1), std::end(re1_1), re1_2.begin(), re1_2.end())); - StringSplitLvalue_SplitBySingeChar::without_char(); -} -namespace StringSplitLvalue_SplitByCStr { - template::value, std::nullptr_t> = nullptr> - void without_char() - { - using char_type = CharType; - const std::basic_string s2 = constant::arikitarina_sekai_wspace(); - const std::basic_string re2_1[] = { constant::arikitarina(), constant::sekai() }; - const auto re2_2 = s2 | split(constant::wspace()); - IUTEST_ASSERT_TRUE(std::equal(std::begin(re2_1), std::end(re2_1), re2_2.begin(), re2_2.end())); - } - template::value, std::nullptr_t> = nullptr> - void without_char() {} -} -IUTEST_TYPED_TEST(StringSplitLvalue, SplitByCStr) -{ - using char_type = TypeParam; - const std::basic_string s1 = constant::arikitari_na_world_underscore(); - const std::basic_string re1_1[] = { constant::arikitari(), constant::na(), constant::world() }; - const auto re1_2 = s1 | split(constant::space_underscore()); - IUTEST_ASSERT_TRUE(std::equal(std::begin(re1_1), std::end(re1_1), re1_2.begin(), re1_2.end())); - StringSplitLvalue_SplitByCStr::without_char(); -} -namespace StringSplitLvalue_SplitByStlStr { - template::value, std::nullptr_t> = nullptr> - void without_char() - { - using char_type = CharType; - const std::basic_string s2 = constant::arikitarina_sekai_wspace(); - const std::basic_string re2_1[] = { constant::arikitarina(), constant::sekai() }; - const auto re2_2 = s2 | split(std::basic_string(constant::wspace())); - IUTEST_ASSERT_TRUE(std::equal(std::begin(re2_1), std::end(re2_1), re2_2.begin(), re2_2.end())); - } - template::value, std::nullptr_t> = nullptr> - void without_char() {} -} -IUTEST_TYPED_TEST(StringSplitLvalue, SplitByStlStr) -{ - using char_type = TypeParam; - const std::basic_string s1 = constant::arikitari_na_world_underscore(); - const std::basic_string re1_1[] = { constant::arikitari(), constant::na(), constant::world() }; - const auto re1_2 = s1 | split(std::basic_string(constant::space_underscore())); - IUTEST_ASSERT_TRUE(std::equal(std::begin(re1_1), std::end(re1_1), re1_2.begin(), re1_2.end())); - StringSplitLvalue_SplitByStlStr::without_char(); -} -#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW -IUTEST_TYPED_TEST(StringSplitLvalue, SplitByStlStrView) -{ - using char_type = TypeParam; - const std::basic_string s1 = constant::arikitari_na_world_underscore(); - const std::basic_string re1_1[] = { constant::arikitari(), constant::na(), constant::world() }; - const auto re1_2 = s1 | split(std::basic_string_view(constant::space_underscore())); - IUTEST_ASSERT_TRUE(std::equal(std::begin(re1_1), std::end(re1_1), re1_2.begin(), re1_2.end())); - if constexpr(!std::is_same_v) { - const std::basic_string s2 = constant::arikitarina_sekai_wspace(); - const std::basic_string re2_1[] = { constant::arikitarina(), constant::sekai() }; - const auto re2_2 = s2 | split(std::basic_string(constant::wspace())); - IUTEST_ASSERT_TRUE(std::equal(std::begin(re2_1), std::end(re2_1), re2_2.begin(), re2_2.end())); - } -} -#endif -template -struct StringSplitLvalueCovertToInt : public ::iutest::Test {}; -IUTEST_TYPED_TEST_CASE(StringSplitLvalueCovertToInt, ::iutest::Types); -IUTEST_TYPED_TEST(StringSplitLvalueCovertToInt, BySingeChar) -{ - using char_type = TypeParam; - const std::basic_string s = constant::csv_data_123_421_113(); - constexpr std::array re1{ { 123, 421, 113 } }; - const auto re2 = s | split(constant::comma()) >> [](const std::basic_string& s) { - return std::stoi(s); - }; - IUTEST_ASSERT_TRUE(std::equal(re1.begin(), re1.end(), re2.begin(), re2.end())); -} -IUTEST_TYPED_TEST(StringSplitLvalueCovertToInt, ByCStr) -{ - using char_type = TypeParam; - const std::basic_string s = constant::csv_data_123_421_113_with_space(); - constexpr std::array re1{ { 123, 421, 113 } }; - const auto re2 = s | split(constant::space_comma()) >> [](const std::basic_string& s) { - return std::stoi(s); - }; - IUTEST_ASSERT_TRUE(std::equal(re1.begin(), re1.end(), re2.begin(), re2.end())); -} -IUTEST_TYPED_TEST(StringSplitLvalueCovertToInt, ByStlStr) -{ - using char_type = TypeParam; - const std::basic_string s = constant::csv_data_123_421_113_with_space(); - constexpr std::array re1{ { 123, 421, 113 } }; - const auto re2 = s | split(std::basic_string(constant::space_comma())) >> [](const std::basic_string& s) { - return std::stoi(s); - }; - IUTEST_ASSERT_TRUE(std::equal(re1.begin(), re1.end(), re2.begin(), re2.end())); -} -IUTEST_TYPED_TEST(StringSplitLvalueCovertToInt, NoReturnBySingeChar) -{ - using char_type = TypeParam; - const std::basic_string s = constant::csv_data_123_421_113(); - constexpr std::array re1{ { 123, 421, 113 } }; - std::vector re2; - re2.reserve(3); - s | split(constant::comma()) >> [&re2](const std::basic_string& s) { - return re2.push_back(std::stoi(s)); - }; - IUTEST_ASSERT_TRUE(std::equal(re1.begin(), re1.end(), re2.begin(), re2.end())); -} -IUTEST_TYPED_TEST(StringSplitLvalueCovertToInt, NoReturnByCStr) -{ - using char_type = TypeParam; - const std::basic_string s = constant::csv_data_123_421_113_with_space(); - constexpr std::array re1{ { 123, 421, 113 } }; - std::vector re2; - re2.reserve(3); - s | split(constant::space_comma()) >> [&re2](const std::basic_string& s) { - return re2.push_back(std::stoi(s)); - }; - IUTEST_ASSERT_TRUE(std::equal(re1.begin(), re1.end(), re2.begin(), re2.end())); -} -IUTEST_TYPED_TEST(StringSplitLvalueCovertToInt, NoReturnByStlStr) -{ - using char_type = TypeParam; - const std::basic_string s = constant::csv_data_123_421_113_with_space(); - constexpr std::array re1{ { 123, 421, 113 } }; - std::vector re2; - re2.reserve(3); - s | split(std::basic_string(constant::space_comma())) >> [&re2](const std::basic_string& s) { - return re2.push_back(std::stoi(s)); - }; - IUTEST_ASSERT_TRUE(std::equal(re1.begin(), re1.end(), re2.begin(), re2.end())); -} -template -struct StringSplitRvalue : public ::iutest::Test {}; -IUTEST_TYPED_TEST_CASE(StringSplitRvalue, ::iutest::Types); -IUTEST_TYPED_TEST(StringSplitRvalue, chain_front_by_singe_char) -{ - using char_type = TypeParam; - using s = std::basic_string; - const auto re = s(constant::cpp_basic_istream()) | split(constant::space()) >> front(); - IUTEST_ASSERT_EQ(constant::cpp_basic_istream_part(), re); -} -IUTEST_TYPED_TEST(StringSplitRvalue, chain_front_by_c_str) -{ - using char_type = TypeParam; - using s = std::basic_string; - constexpr auto delim = constant::space_underscore(); - const auto re = s(constant::arikitari_na_world_underscore()) | split(delim) >> front(); - IUTEST_ASSERT_EQ(constant::arikitari(), re); -} -IUTEST_TYPED_TEST(StringSplitRvalue, chain_front_by_stl_str) -{ - using char_type = TypeParam; - using s = std::basic_string; - const s delim = constant::space_underscore(); - const auto re = s(constant::arikitari_na_world_underscore()) | split(delim) >> front(); - IUTEST_ASSERT_EQ(constant::arikitari(), re); -} -#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW -IUTEST_TYPED_TEST(StringSplitRvalue, chain_front_by_stl_str_view) -{ - using char_type = TypeParam; - using s = std::basic_string; - const std::basic_string_view delim = constant::space_underscore(); - const auto re = s(constant::arikitari_na_world_underscore()) | split(delim) >> front(); - IUTEST_ASSERT_EQ(constant::arikitari(), re); -} -#endif -IUTEST_TYPED_TEST(StringSplitRvalue, chain_back_by_singe_char) -{ - using char_type = TypeParam; - using s = std::basic_string; - const auto re = s(constant::arikitari_na_world()) | split(constant::space()) >> back(); - IUTEST_ASSERT_EQ(constant::world(), re); -} -IUTEST_TYPED_TEST(StringSplitRvalue, chain_back_by_c_str) -{ - using char_type = TypeParam; - using s = std::basic_string; - constexpr auto delim = constant::space_underscore(); - const auto re = s(constant::arikitari_na_world_underscore()) | split(delim) >> back(); - IUTEST_ASSERT_EQ(constant::world(), re); -} -IUTEST_TYPED_TEST(StringSplitRvalue, chain_back_by_stl_str) -{ - using char_type = TypeParam; - using s = std::basic_string; - const s delim = constant::space_underscore(); - const auto re = s(constant::arikitari_na_world_underscore()) | split(delim) >> back(); - IUTEST_ASSERT_EQ(constant::world(), re); -} -#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW -IUTEST_TYPED_TEST(StringSplitRvalue, chain_back_by_stl_str_view) -{ - using char_type = TypeParam; - using s = std::basic_string; - const std::basic_string_view delim = constant::space_underscore(); - const auto re = s(constant::arikitari_na_world_underscore()) | split(delim) >> back(); - IUTEST_ASSERT_EQ(constant::world(), re); -} -#endif -IUTEST_TYPED_TEST(StringSplitRvalue, chain_at_first_front) -{ - using char_type = TypeParam; - using s = std::basic_string; - const auto re = s(constant::cpp_type_data2()) | split(constant::space()) >> at_first().front(); - IUTEST_ASSERT_EQ(constant::cpp_dxle_sound_c(), re); -} -IUTEST_TYPED_TEST(StringSplitRvalue, chain_at_first_back_by_single_char) -{ - using char_type = TypeParam; - using s = std::basic_string; - const auto re = s(constant::cpp_type_data2()) | split(constant::space()) >> at_first().back(); - IUTEST_ASSERT_EQ(constant::cpp_LoadSoundMem(), re); -} -IUTEST_TYPED_TEST(StringSplitRvalue, chain_at_first_back_by_c_str) -{ - using char_type = TypeParam; - using s = std::basic_string; - const auto re = s(constant::arikitari_na_world_underscore()) - | split(constant::space_underscore()) >> at_first().back(); - IUTEST_ASSERT_EQ(constant::na_world(), re); -} -IUTEST_TYPED_TEST(StringSplitRvalue, chain_at_first_back_by_stl_str) -{ - using char_type = TypeParam; - using s = std::basic_string; - const auto re = s(constant::arikitari_na_world_underscore()) - | split(s(constant::space_underscore())) >> at_first().back(); - IUTEST_ASSERT_EQ(constant::na_world(), re); -} -IUTEST_TYPED_TEST(StringSplitRvalue, chain_at_first_by_single_char) -{ - using char_type = TypeParam; - using s = std::basic_string; - const auto re = s(constant::cpp_type_data2()) | split(constant::space()) >> at_first(); - IUTEST_ASSERT(2u == re.size()); - IUTEST_ASSERT_EQ(constant::cpp_dxle_sound_c(), re[0]); - IUTEST_ASSERT_EQ(constant::cpp_LoadSoundMem(), re[1]); -} -IUTEST_TYPED_TEST(StringSplitRvalue, chain_at_first_by_c_str) -{ - using char_type = TypeParam; - using s = std::basic_string; - const auto re = s(constant::arikitari_na_world_underscore()) | split(constant::space_underscore()) >> at_first(); - IUTEST_ASSERT(2u == re.size()); - IUTEST_ASSERT_EQ(constant::arikitari(), re[0]); - IUTEST_ASSERT_EQ(constant::na_world(), re[1]); -} -IUTEST_TYPED_TEST(StringSplitRvalue, chain_at_first_by_stl_str) -{ - using char_type = TypeParam; - using s = std::basic_string; - const auto re = s(constant::arikitari_na_world_underscore()) | split(s(constant::space_underscore())) >> at_first(); - IUTEST_ASSERT(2u == re.size()); - IUTEST_ASSERT_EQ(constant::arikitari(), re[0]); - IUTEST_ASSERT_EQ(constant::na_world(), re[1]); -} -IUTEST_TYPED_TEST(StringSplitRvalue, chain_at_last_front_by_single_char) -{ - using char_type = TypeParam; - using s = std::basic_string; - const auto re = s(constant::cpp_type_data1()) | split(constant::colon()) >> at_last().front(); - IUTEST_ASSERT_EQ(constant::cpp_basic_istream(), re); -} -IUTEST_TYPED_TEST(StringSplitRvalue, chain_at_last_front_by_c_str) -{ - using char_type = TypeParam; - using s = std::basic_string; - const auto re = s(constant::arikitari_na_world_underscore()) - | split(constant::space_underscore()) >> at_last().front(); - IUTEST_ASSERT_EQ(constant::arikitari_na(), re); -} -IUTEST_TYPED_TEST(StringSplitRvalue, chain_at_last_front_by_stl_str) -{ - using char_type = TypeParam; - using s = std::basic_string; - const auto re = s(constant::arikitari_na_world_underscore()) - | split(s(constant::space_underscore())) >> at_last().front(); - IUTEST_ASSERT_EQ(constant::arikitari_na(), re); -} -IUTEST_TYPED_TEST(StringSplitRvalue, chain_at_last_back) -{ - using char_type = TypeParam; - using s = std::basic_string; - const auto re = s(constant::cpp_type_data1()) | split(constant::colon()) >> at_last().back(); - IUTEST_ASSERT_EQ(constant::ignore(), re); -} -IUTEST_TYPED_TEST(StringSplitRvalue, chain_at_last_by_single_char) -{ - using char_type = TypeParam; - using s = std::basic_string; - const auto re = s(constant::cpp_type_data1()) | split(constant::colon()) >> at_last(); - IUTEST_ASSERT(2u == re.size()); - IUTEST_ASSERT_EQ(constant::cpp_basic_istream(), re[0]); - IUTEST_ASSERT_EQ(constant::ignore(), re[1]); -} -IUTEST_TYPED_TEST(StringSplitRvalue, chain_at_last_by_c_str) -{ - using char_type = TypeParam; - using s = std::basic_string; - const auto re = s(constant::arikitari_na_world_underscore()) | split(constant::space_underscore()) >> at_last(); - IUTEST_ASSERT(2u == re.size()); - IUTEST_ASSERT_EQ(constant::arikitari_na(), re[0]); - IUTEST_ASSERT_EQ(constant::world(), re[1]); -} -IUTEST_TYPED_TEST(StringSplitRvalue, chain_at_last_by_stl_str) -{ - using char_type = TypeParam; - using s = std::basic_string; - const auto re = s(constant::arikitari_na_world_underscore()) | split(s(constant::space_underscore())) >> at_last(); - IUTEST_ASSERT(2u == re.size()); - IUTEST_ASSERT_EQ(constant::arikitari_na(), re[0]); - IUTEST_ASSERT_EQ(constant::world(), re[1]); -} -IUTEST_TYPED_TEST(StringSplitRvalue, ExtractBySingeChar) -{ - using char_type = TypeParam; - using s = std::basic_string; - using lim = std::numeric_limits; - constexpr char_type space = constant::space(); - IUTEST_ASSERT_EQ(constant::arikitari(), s(constant::arikitari_na_world()) | split(space)[0]); - IUTEST_ASSERT_EQ(constant::na(), s(constant::arikitari_na_world()) | split(space)[1]); - IUTEST_ASSERT_EQ(constant::world(), s(constant::arikitari_na_world()) | split(space)[2]); - IUTEST_EXPECT_THROW(s(constant::arikitari_na_world()) | split(space)[3], std::out_of_range); - IUTEST_EXPECT_THROW(s(constant::arikitari_na_world()) | split(space)[5], std::out_of_range); - IUTEST_EXPECT_THROW(s(constant::arikitari_na_world()) | split(space)[3250], std::out_of_range); - IUTEST_EXPECT_THROW(s(constant::arikitari_na_world()) | split(space)[lim::max()], std::out_of_range); -} -IUTEST_TYPED_TEST(StringSplitRvalue, ExtractByCStr) -{ - using char_type = TypeParam; - using s = std::basic_string; - using lim = std::numeric_limits; - const auto delim = constant::space_underscore(); - IUTEST_ASSERT_EQ(constant::arikitari(), s(constant::arikitari_na_world_underscore()) | split(delim)[0]); - IUTEST_ASSERT_EQ(constant::na(), s(constant::arikitari_na_world_underscore()) | split(delim)[1]); - IUTEST_ASSERT_EQ(constant::world(), s(constant::arikitari_na_world_underscore()) | split(delim)[2]); - IUTEST_EXPECT_THROW(s(constant::arikitari_na_world_underscore()) | split(delim)[3], std::out_of_range); - IUTEST_EXPECT_THROW(s(constant::arikitari_na_world_underscore()) | split(delim)[5], std::out_of_range); - IUTEST_EXPECT_THROW(s(constant::arikitari_na_world_underscore()) | split(delim)[3250], std::out_of_range); - IUTEST_EXPECT_THROW(s(constant::arikitari_na_world_underscore()) | split(delim)[lim::max()], std::out_of_range); -} -IUTEST_TYPED_TEST(StringSplitRvalue, ExtractByStlStr) -{ - using char_type = TypeParam; - using s = std::basic_string; - using lim = std::numeric_limits; - const s delim = constant::space_underscore(); - IUTEST_ASSERT_EQ(constant::arikitari(), s(constant::arikitari_na_world_underscore()) | split(delim)[0]); - IUTEST_ASSERT_EQ(constant::na(), s(constant::arikitari_na_world_underscore()) | split(delim)[1]); - IUTEST_ASSERT_EQ(constant::world(), s(constant::arikitari_na_world_underscore()) | split(delim)[2]); - IUTEST_EXPECT_THROW(s(constant::arikitari_na_world_underscore()) | split(delim)[3], std::out_of_range); - IUTEST_EXPECT_THROW(s(constant::arikitari_na_world_underscore()) | split(delim)[5], std::out_of_range); - IUTEST_EXPECT_THROW(s(constant::arikitari_na_world_underscore()) | split(delim)[3250], std::out_of_range); - IUTEST_EXPECT_THROW(s(constant::arikitari_na_world_underscore()) | split(delim)[lim::max()], std::out_of_range); -} -#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW -IUTEST_TYPED_TEST(StringSplitRvalue, ExtractByStlStrView) -{ - using char_type = TypeParam; - using s = std::basic_string; - using lim = std::numeric_limits; - const std::basic_string_view delim = constant::space_underscore(); - IUTEST_ASSERT_EQ(constant::arikitari(), s(constant::arikitari_na_world_underscore()) | split(delim)[0]); - IUTEST_ASSERT_EQ(constant::na(), s(constant::arikitari_na_world_underscore()) | split(delim)[1]); - IUTEST_ASSERT_EQ(constant::world(), s(constant::arikitari_na_world_underscore()) | split(delim)[2]); - IUTEST_EXPECT_THROW(s(constant::arikitari_na_world_underscore()) | split(delim)[3], std::out_of_range); - IUTEST_EXPECT_THROW(s(constant::arikitari_na_world_underscore()) | split(delim)[5], std::out_of_range); - IUTEST_EXPECT_THROW(s(constant::arikitari_na_world_underscore()) | split(delim)[3250], std::out_of_range); - IUTEST_EXPECT_THROW(s(constant::arikitari_na_world_underscore()) | split(delim)[lim::max()], std::out_of_range); -} -#endif -namespace StringSplitRvalue_SplitBySingeChar { - template::value, std::nullptr_t> = nullptr> - void without_char() - { - using char_type = CharType; - using s = std::basic_string; - const s re2_1[] = { constant::arikitarina(), constant::sekai() }; - const auto re2_2 = s(constant::arikitarina_sekai()) | split(constant::space()); - IUTEST_ASSERT_TRUE(std::equal(std::begin(re2_1), std::end(re2_1), re2_2.begin(), re2_2.end())); - } - template::value, std::nullptr_t> = nullptr> - void without_char() {} -} -IUTEST_TYPED_TEST(StringSplitRvalue, SplitBySingeChar) -{ - using char_type = TypeParam; - using s = std::basic_string; - const s re1_1[] = { constant::arikitari(), constant::na(), constant::world() }; - const auto re1_2 = s(constant::arikitari_na_world()) | split(constant::space()); - IUTEST_ASSERT_TRUE(std::equal(std::begin(re1_1), std::end(re1_1), re1_2.begin(), re1_2.end())); - StringSplitRvalue_SplitBySingeChar::without_char(); -} -namespace StringSplitRvalue_SplitByCStr { - template::value, std::nullptr_t> = nullptr> - void without_char() - { - using char_type = CharType; - using s = std::basic_string; - const s re2_1[] = { constant::arikitarina(), constant::sekai() }; - const auto re2_2 = s(constant::arikitarina_sekai_wspace()) | split(constant::wspace()); - IUTEST_ASSERT_TRUE(std::equal(std::begin(re2_1), std::end(re2_1), re2_2.begin(), re2_2.end())); - } - template::value, std::nullptr_t> = nullptr> - void without_char() {} -} -IUTEST_TYPED_TEST(StringSplitRvalue, SplitByCStr) -{ - using char_type = TypeParam; - using s = std::basic_string; - const s re1_1[] = { constant::arikitari(), constant::na(), constant::world() }; - const auto re1_2 = s(constant::arikitari_na_world_underscore()) | split(constant::space_underscore()); - IUTEST_ASSERT_TRUE(std::equal(std::begin(re1_1), std::end(re1_1), re1_2.begin(), re1_2.end())); - StringSplitLvalue_SplitByCStr::without_char(); -} -namespace StringSplitRvalue_SplitByStlStr{ - template::value, std::nullptr_t> = nullptr> - void without_char() - { - using char_type = CharType; - using s = std::basic_string; - const s re2_1[] = { constant::arikitarina(), constant::sekai() }; - const auto re2_2 = s(constant::arikitarina_sekai_wspace()) | split(s(constant::wspace())); - IUTEST_ASSERT_TRUE(std::equal(std::begin(re2_1), std::end(re2_1), re2_2.begin(), re2_2.end())); - } - template::value, std::nullptr_t> = nullptr> - void without_char() {} -} -IUTEST_TYPED_TEST(StringSplitRvalue, SplitByStlStr) -{ - using char_type = TypeParam; - using s = std::basic_string; - const s re1_1[] = { constant::arikitari(), constant::na(), constant::world() }; - const auto re1_2 = s(constant::arikitari_na_world_underscore()) | split(s(constant::space_underscore())); - IUTEST_ASSERT_TRUE(std::equal(std::begin(re1_1), std::end(re1_1), re1_2.begin(), re1_2.end())); - StringSplitLvalue_SplitByCStr::without_char(); -} -template -struct StringSplitRvalueCovertToInt : public ::iutest::Test {}; -IUTEST_TYPED_TEST_CASE(StringSplitRvalueCovertToInt, ::iutest::Types); -IUTEST_TYPED_TEST(StringSplitRvalueCovertToInt, BySingeChar) -{ - using char_type = TypeParam; - using s = std::basic_string; - constexpr std::array re1{ { 123, 421, 113 } }; - const auto re2 = s(constant::csv_data_123_421_113()) | split(constant::comma()) >> [](const s& s) { - return std::stoi(s); - }; - IUTEST_ASSERT_TRUE(std::equal(re1.begin(), re1.end(), re2.begin(), re2.end())); -} -IUTEST_TYPED_TEST(StringSplitRvalueCovertToInt, ByCStr) -{ - using char_type = TypeParam; - using s = std::basic_string; - constexpr std::array re1{ { 123, 421, 113 } }; - const auto re2 = s(constant::csv_data_123_421_113_with_space()) | split(constant::space_comma()) >> [](const s& s) { - return std::stoi(s); - }; - IUTEST_ASSERT_TRUE(std::equal(re1.begin(), re1.end(), re2.begin(), re2.end())); -} -IUTEST_TYPED_TEST(StringSplitRvalueCovertToInt, ByStlStr) -{ - using char_type = TypeParam; - using s = std::basic_string; - constexpr std::array re1{ { 123, 421, 113 } }; - const auto re2 = s(constant::csv_data_123_421_113_with_space()) | split(s(constant::space_comma())) >> [](const s& s) { - return std::stoi(s); - }; - IUTEST_ASSERT_TRUE(std::equal(re1.begin(), re1.end(), re2.begin(), re2.end())); -} -IUTEST_TYPED_TEST(StringSplitRvalueCovertToInt, NoReturnBySingeChar) -{ - using char_type = TypeParam; - using s = std::basic_string; - constexpr std::array re1{ { 123, 421, 113 } }; - std::vector re2; - re2.reserve(3); - s(constant::csv_data_123_421_113()) | split(constant::comma()) >> [&re2](const s& s) { - re2.push_back(std::stoi(s)); - }; - IUTEST_ASSERT_TRUE(std::equal(re1.begin(), re1.end(), re2.begin(), re2.end())); -} -IUTEST_TYPED_TEST(StringSplitRvalueCovertToInt, NoReturnByCStr) -{ - using char_type = TypeParam; - using s = std::basic_string; - constexpr std::array re1{ { 123, 421, 113 } }; - std::vector re2; - re2.reserve(3); - s(constant::csv_data_123_421_113_with_space()) | split(constant::space_comma()) >> [&re2](const s& s) { - re2.push_back(std::stoi(s)); - }; - IUTEST_ASSERT_TRUE(std::equal(re1.begin(), re1.end(), re2.begin(), re2.end())); -} -IUTEST_TYPED_TEST(StringSplitRvalueCovertToInt, NoReturnByStlStr) -{ - using char_type = TypeParam; - using s = std::basic_string; - constexpr std::array re1{ { 123, 421, 113 } }; - std::vector re2; - re2.reserve(3); - s(constant::csv_data_123_421_113_with_space()) | split(s(constant::space_comma())) >> [&re2](const s& s) { - re2.push_back(std::stoi(s)); - }; - IUTEST_ASSERT_TRUE(std::equal(re1.begin(), re1.end(), re2.begin(), re2.end())); -} - int main(int argc, char** argv) { IUTEST_INIT(&argc, argv); return IUTEST_RUN_ALL_TESTS(); -} \ No newline at end of file +} diff --git a/test/test_cxx17_string_view.cpp b/test/test_cxx17_string_view.cpp index c7880ef..bc45868 100644 --- a/test/test_cxx17_string_view.cpp +++ b/test/test_cxx17_string_view.cpp @@ -1,4 +1,10 @@ -#include "../include/string_split.hpp" +/*============================================================================= + Copyright (C) 2016 yumetodo + + Distributed under the Boost Software License, Version 1.0. + (See http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#include "../include/string_split.hpp" #ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW #include "../iutest/include/iutest.hpp" #include "constant.hpp" diff --git a/test/test_lvalue.cpp b/test/test_lvalue.cpp new file mode 100644 index 0000000..1de9fcb --- /dev/null +++ b/test/test_lvalue.cpp @@ -0,0 +1,456 @@ +/*============================================================================= + Copyright (C) 2016 yumetodo + + Distributed under the Boost Software License, Version 1.0. + (See http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#include "../include/string_split.hpp" +#include "../iutest/include/iutest.hpp" +#include "constant.hpp" +#include +#include +#include +template +struct StringSplitLvalue : public ::iutest::Test {}; +IUTEST_TYPED_TEST_CASE(StringSplitLvalue, ::iutest::Types); +IUTEST_TYPED_TEST(StringSplitLvalue, chain_front_by_singe_char) +{ + using char_type = TypeParam; + const std::basic_string s = constant::cpp_basic_istream(); + const auto re = s | split(constant::space()) >> front(); + IUTEST_ASSERT_EQ(constant::cpp_basic_istream_part(), re); +} +IUTEST_TYPED_TEST(StringSplitLvalue, chain_front_by_c_str) +{ + using char_type = TypeParam; + const std::basic_string s = constant::arikitari_na_world_underscore(); + constexpr auto delim = constant::space_underscore(); + IUTEST_ASSERT_EQ(constant::arikitari(), s | split(delim) >> front()); +} +IUTEST_TYPED_TEST(StringSplitLvalue, chain_front_by_stl_str) +{ + using char_type = TypeParam; + const std::basic_string s = constant::arikitari_na_world_underscore(); + const std::basic_string delim = constant::space_underscore(); + IUTEST_ASSERT_EQ(constant::arikitari(), s | split(delim) >> front()); +} +#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW +IUTEST_TYPED_TEST(StringSplitLvalue, chain_front_by_stl_str_view) +{ + using char_type = TypeParam; + const std::basic_string s = constant::arikitari_na_world_underscore(); + const std::basic_string_view delim = constant::space_underscore(); + IUTEST_ASSERT_EQ(constant::arikitari(), s | split(delim) >> front()); +} +#endif +IUTEST_TYPED_TEST(StringSplitLvalue, chain_back_by_singe_char) +{ + using char_type = TypeParam; + const std::basic_string s = constant::arikitari_na_world(); + const auto re = s | split(constant::space()) >> back(); + IUTEST_ASSERT_EQ(constant::world(), re); +} +IUTEST_TYPED_TEST(StringSplitLvalue, chain_back_by_c_str) +{ + using char_type = TypeParam; + const std::basic_string s = constant::arikitari_na_world_underscore(); + constexpr auto delim = constant::space_underscore(); + IUTEST_ASSERT_EQ(constant::world(), s | split(delim) >> back()); +} +IUTEST_TYPED_TEST(StringSplitLvalue, chain_back_by_stl_str) +{ + using char_type = TypeParam; + const std::basic_string s = constant::arikitari_na_world_underscore(); + const std::basic_string delim = constant::space_underscore(); + IUTEST_ASSERT_EQ(constant::world(), s | split(delim) >> back()); +} +#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW +IUTEST_TYPED_TEST(StringSplitLvalue, chain_back_by_stl_str_view) +{ + using char_type = TypeParam; + const std::basic_string s = constant::arikitari_na_world_underscore(); + const std::basic_string_view delim = constant::space_underscore(); + IUTEST_ASSERT_EQ(constant::world(), s | split(delim) >> back()); +} +#endif +IUTEST_TYPED_TEST(StringSplitLvalue, chain_at_first_front) +{ + using char_type = TypeParam; + const std::basic_string s = constant::cpp_type_data2(); + const auto re = s | split(constant::space()) >> at_first().front(); + IUTEST_ASSERT_EQ(constant::cpp_dxle_sound_c(), re); +} +IUTEST_TYPED_TEST(StringSplitLvalue, chain_at_first_back_by_single_char) +{ + using char_type = TypeParam; + const std::basic_string s = constant::cpp_type_data2(); + const auto re = s | split(constant::space()) >> at_first().back(); + IUTEST_ASSERT_EQ(constant::cpp_LoadSoundMem(), re); +} +IUTEST_TYPED_TEST(StringSplitLvalue, chain_at_first_back_by_c_str) +{ + using char_type = TypeParam; + const std::basic_string s = constant::arikitari_na_world_underscore(); + const auto re = s | split(constant::space_underscore()) >> at_first().back(); + IUTEST_ASSERT_EQ(constant::na_world(), re); +} +IUTEST_TYPED_TEST(StringSplitLvalue, chain_at_first_back_by_stl_str) +{ + using char_type = TypeParam; + const std::basic_string s = constant::arikitari_na_world_underscore(); + const auto re = s | split(std::basic_string(constant::space_underscore())) >> at_first().back(); + IUTEST_ASSERT_EQ(constant::na_world(), re); +} +#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW +IUTEST_TYPED_TEST(StringSplitLvalue, chain_at_first_back_by_stl_str_view) +{ + using char_type = TypeParam; + const std::basic_string s = constant::arikitari_na_world_underscore(); + const auto re = s | split(std::basic_string_view(constant::space_underscore())) >> at_first().back(); + IUTEST_ASSERT_EQ(constant::na_world(), re); +} +#endif +IUTEST_TYPED_TEST(StringSplitLvalue, chain_at_first_by_single_char) +{ + using char_type = TypeParam; + const std::basic_string s = constant::cpp_type_data2(); + const auto re = s | split(constant::space()) >> at_first(); + IUTEST_ASSERT(2u == re.size()); + IUTEST_ASSERT_EQ(constant::cpp_dxle_sound_c(), re[0]); + IUTEST_ASSERT_EQ(constant::cpp_LoadSoundMem(), re[1]); +} +IUTEST_TYPED_TEST(StringSplitLvalue, chain_at_first_by_c_str) +{ + using char_type = TypeParam; + const std::basic_string s = constant::arikitari_na_world_underscore(); + const auto re = s | split(constant::space_underscore()) >> at_first(); + IUTEST_ASSERT(2u == re.size()); + IUTEST_ASSERT_EQ(constant::arikitari(), re[0]); + IUTEST_ASSERT_EQ(constant::na_world(), re[1]); +} +IUTEST_TYPED_TEST(StringSplitLvalue, chain_at_first_by_stl_str) +{ + using char_type = TypeParam; + const std::basic_string s = constant::arikitari_na_world_underscore(); + const auto re = s | split(std::basic_string(constant::space_underscore())) >> at_first(); + IUTEST_ASSERT(2u == re.size()); + IUTEST_ASSERT_EQ(constant::arikitari(), re[0]); + IUTEST_ASSERT_EQ(constant::na_world(), re[1]); +} +#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW +IUTEST_TYPED_TEST(StringSplitLvalue, chain_at_first_by_stl_str_view) +{ + using char_type = TypeParam; + const std::basic_string s = constant::arikitari_na_world_underscore(); + const auto re = s | split(std::basic_string_view(constant::space_underscore())) >> at_first(); + IUTEST_ASSERT(2u == re.size()); + IUTEST_ASSERT_EQ(constant::arikitari(), re[0]); + IUTEST_ASSERT_EQ(constant::na_world(), re[1]); +} +#endif +IUTEST_TYPED_TEST(StringSplitLvalue, chain_at_last_front_by_single_char) +{ + using char_type = TypeParam; + const std::basic_string s = constant::cpp_type_data1(); + const auto re = s | split(constant::colon()) >> at_last().front(); + IUTEST_ASSERT_EQ(constant::cpp_basic_istream(), re); +} +IUTEST_TYPED_TEST(StringSplitLvalue, chain_at_last_front_by_c_str) +{ + using char_type = TypeParam; + const std::basic_string s = constant::arikitari_na_world_underscore(); + const auto re = s | split(constant::space_underscore()) >> at_last().front(); + IUTEST_ASSERT_EQ(constant::arikitari_na(), re); +} +IUTEST_TYPED_TEST(StringSplitLvalue, chain_at_last_front_by_stl_str) +{ + using char_type = TypeParam; + const std::basic_string s = constant::arikitari_na_world_underscore(); + const auto re = s | split(std::basic_string(constant::space_underscore())) >> at_last().front(); + IUTEST_ASSERT_EQ(constant::arikitari_na(), re); +} +#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW +IUTEST_TYPED_TEST(StringSplitLvalue, chain_at_last_front_by_stl_str_view) +{ + using char_type = TypeParam; + const std::basic_string s = constant::arikitari_na_world_underscore(); + const auto re = s | split(std::basic_string_view(constant::space_underscore())) >> at_last().front(); + IUTEST_ASSERT_EQ(constant::arikitari_na(), re); +} +#endif +IUTEST_TYPED_TEST(StringSplitLvalue, chain_at_last_back) +{ + using char_type = TypeParam; + const std::basic_string s = constant::cpp_type_data1(); + const auto re = s | split(constant::colon()) >> at_last().back(); + IUTEST_ASSERT_EQ(constant::ignore(), re); +} +IUTEST_TYPED_TEST(StringSplitLvalue, chain_at_last_by_single_char) +{ + using char_type = TypeParam; + const std::basic_string s = constant::cpp_type_data1(); + const auto re = s | split(constant::colon()) >> at_last(); + IUTEST_ASSERT(2u == re.size()); + IUTEST_ASSERT_EQ(constant::cpp_basic_istream(), re[0]); + IUTEST_ASSERT_EQ(constant::ignore(), re[1]); +} +IUTEST_TYPED_TEST(StringSplitLvalue, chain_at_last_by_c_str) +{ + using char_type = TypeParam; + const std::basic_string s = constant::arikitari_na_world_underscore(); + const auto re = s | split(constant::space_underscore()) >> at_last(); + IUTEST_ASSERT(2u == re.size()); + IUTEST_ASSERT_EQ(constant::arikitari_na(), re[0]); + IUTEST_ASSERT_EQ(constant::world(), re[1]); +} +IUTEST_TYPED_TEST(StringSplitLvalue, chain_at_last_by_stl_str) +{ + using char_type = TypeParam; + const std::basic_string s = constant::arikitari_na_world_underscore(); + const auto re = s | split(std::basic_string(constant::space_underscore())) >> at_last(); + IUTEST_ASSERT(2u == re.size()); + IUTEST_ASSERT_EQ(constant::arikitari_na(), re[0]); + IUTEST_ASSERT_EQ(constant::world(), re[1]); +} +#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW +IUTEST_TYPED_TEST(StringSplitLvalue, chain_at_last_by_stl_str_view) +{ + using char_type = TypeParam; + const std::basic_string s = constant::arikitari_na_world_underscore(); + const auto re = s | split(std::basic_string_view(constant::space_underscore())) >> at_last(); + IUTEST_ASSERT(2u == re.size()); + IUTEST_ASSERT_EQ(constant::arikitari_na(), re[0]); + IUTEST_ASSERT_EQ(constant::world(), re[1]); +} +#endif +IUTEST_TYPED_TEST(StringSplitLvalue, ExtractBySingeChar) +{ + using char_type = TypeParam; + constexpr char_type space = constant::space(); + const std::basic_string s = constant::arikitari_na_world(); + IUTEST_ASSERT_EQ(constant::arikitari(), s | split(space)[0]); + IUTEST_ASSERT_EQ(constant::na(), s | split(space)[1]); + IUTEST_ASSERT_EQ(constant::world(), s | split(space)[2]); + IUTEST_EXPECT_THROW(s | split(space)[3], std::out_of_range); + IUTEST_EXPECT_THROW(s | split(space)[5], std::out_of_range); + IUTEST_EXPECT_THROW(s | split(space)[3250], std::out_of_range); + IUTEST_EXPECT_THROW(s | split(space)[std::numeric_limits::max()], std::out_of_range); +} +IUTEST_TYPED_TEST(StringSplitLvalue, ExtractByCStr) +{ + using char_type = TypeParam; + const std::basic_string s = constant::arikitari_na_world_underscore(); + constexpr auto delim = constant::space_underscore(); + IUTEST_ASSERT_EQ(constant::arikitari(), s | split(delim)[0]); + IUTEST_ASSERT_EQ(constant::na(), s | split(delim)[1]); + IUTEST_ASSERT_EQ(constant::world(), s | split(delim)[2]); + IUTEST_EXPECT_THROW(s | split(delim)[3], std::out_of_range); + IUTEST_EXPECT_THROW(s | split(delim)[5], std::out_of_range); + IUTEST_EXPECT_THROW(s | split(delim)[3250], std::out_of_range); + IUTEST_EXPECT_THROW(s | split(delim)[std::numeric_limits::max()], std::out_of_range); +} +IUTEST_TYPED_TEST(StringSplitLvalue, ExtractByStlStr) +{ + using char_type = TypeParam; + const std::basic_string s = constant::arikitari_na_world_underscore(); + const std::basic_string delim = constant::space_underscore(); + IUTEST_ASSERT_EQ(constant::arikitari(), s | split(delim)[0]); + IUTEST_ASSERT_EQ(constant::na(), s | split(delim)[1]); + IUTEST_ASSERT_EQ(constant::world(), s | split(delim)[2]); + IUTEST_EXPECT_THROW(s | split(delim)[3], std::out_of_range); + IUTEST_EXPECT_THROW(s | split(delim)[5], std::out_of_range); + IUTEST_EXPECT_THROW(s | split(delim)[3250], std::out_of_range); + IUTEST_EXPECT_THROW(s | split(delim)[std::numeric_limits::max()], std::out_of_range); +} +#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW +IUTEST_TYPED_TEST(StringSplitLvalue, ExtractByStlStrView) +{ + using char_type = TypeParam; + const std::basic_string s = constant::arikitari_na_world_underscore(); + const std::basic_string_view delim = constant::space_underscore(); + IUTEST_ASSERT_EQ(constant::arikitari(), s | split(delim)[0]); + IUTEST_ASSERT_EQ(constant::na(), s | split(delim)[1]); + IUTEST_ASSERT_EQ(constant::world(), s | split(delim)[2]); + IUTEST_EXPECT_THROW(s | split(delim)[3], std::out_of_range); + IUTEST_EXPECT_THROW(s | split(delim)[5], std::out_of_range); + IUTEST_EXPECT_THROW(s | split(delim)[3250], std::out_of_range); + IUTEST_EXPECT_THROW(s | split(delim)[std::numeric_limits::max()], std::out_of_range); +} +#endif +namespace StringSplitLvalue_SplitBySingeChar { + template::value, std::nullptr_t> = nullptr> + void without_char() + { + using char_type = CharType; + const std::basic_string s2 = constant::arikitarina_sekai(); + const std::basic_string re2_1[] = { constant::arikitarina(), constant::sekai() }; + const auto re2_2 = s2 | split(constant::space()); + IUTEST_ASSERT_TRUE(std::equal(std::begin(re2_1), std::end(re2_1), re2_2.begin(), re2_2.end())); + } + template::value, std::nullptr_t> = nullptr> + void without_char(){} +} +IUTEST_TYPED_TEST(StringSplitLvalue, SplitBySingeChar) +{ + using char_type = TypeParam; + const std::basic_string s1 = constant::arikitari_na_world(); + const std::basic_string re1_1[] = { constant::arikitari(), constant::na(), constant::world() }; + const auto re1_2 = s1 | split(constant::space()); + IUTEST_ASSERT_TRUE(std::equal(std::begin(re1_1), std::end(re1_1), re1_2.begin(), re1_2.end())); + StringSplitLvalue_SplitBySingeChar::without_char(); +} +namespace StringSplitLvalue_SplitByCStr { + template::value, std::nullptr_t> = nullptr> + void without_char() + { + using char_type = CharType; + const std::basic_string s2 = constant::arikitarina_sekai_wspace(); + const std::basic_string re2_1[] = { constant::arikitarina(), constant::sekai() }; + const auto re2_2 = s2 | split(constant::wspace()); + IUTEST_ASSERT_TRUE(std::equal(std::begin(re2_1), std::end(re2_1), re2_2.begin(), re2_2.end())); + } + template::value, std::nullptr_t> = nullptr> + void without_char() {} +} +IUTEST_TYPED_TEST(StringSplitLvalue, SplitByCStr) +{ + using char_type = TypeParam; + const std::basic_string s1 = constant::arikitari_na_world_underscore(); + const std::basic_string re1_1[] = { constant::arikitari(), constant::na(), constant::world() }; + const auto re1_2 = s1 | split(constant::space_underscore()); + IUTEST_ASSERT_TRUE(std::equal(std::begin(re1_1), std::end(re1_1), re1_2.begin(), re1_2.end())); + StringSplitLvalue_SplitByCStr::without_char(); +} +namespace StringSplitLvalue_SplitByStlStr { + template::value, std::nullptr_t> = nullptr> + void without_char() + { + using char_type = CharType; + const std::basic_string s2 = constant::arikitarina_sekai_wspace(); + const std::basic_string re2_1[] = { constant::arikitarina(), constant::sekai() }; + const auto re2_2 = s2 | split(std::basic_string(constant::wspace())); + IUTEST_ASSERT_TRUE(std::equal(std::begin(re2_1), std::end(re2_1), re2_2.begin(), re2_2.end())); + } + template::value, std::nullptr_t> = nullptr> + void without_char() {} +} +IUTEST_TYPED_TEST(StringSplitLvalue, SplitByStlStr) +{ + using char_type = TypeParam; + const std::basic_string s1 = constant::arikitari_na_world_underscore(); + const std::basic_string re1_1[] = { constant::arikitari(), constant::na(), constant::world() }; + const auto re1_2 = s1 | split(std::basic_string(constant::space_underscore())); + IUTEST_ASSERT_TRUE(std::equal(std::begin(re1_1), std::end(re1_1), re1_2.begin(), re1_2.end())); + StringSplitLvalue_SplitByStlStr::without_char(); +} +#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW +IUTEST_TYPED_TEST(StringSplitLvalue, SplitByStlStrView) +{ + using char_type = TypeParam; + const std::basic_string s1 = constant::arikitari_na_world_underscore(); + const std::basic_string re1_1[] = { constant::arikitari(), constant::na(), constant::world() }; + const auto re1_2 = s1 | split(std::basic_string_view(constant::space_underscore())); + IUTEST_ASSERT_TRUE(std::equal(std::begin(re1_1), std::end(re1_1), re1_2.begin(), re1_2.end())); + if constexpr(!std::is_same_v) { + const std::basic_string s2 = constant::arikitarina_sekai_wspace(); + const std::basic_string re2_1[] = { constant::arikitarina(), constant::sekai() }; + const auto re2_2 = s2 | split(std::basic_string(constant::wspace())); + IUTEST_ASSERT_TRUE(std::equal(std::begin(re2_1), std::end(re2_1), re2_2.begin(), re2_2.end())); + } +} +#endif +template +struct StringSplitLvalueCovertToInt : public ::iutest::Test {}; +IUTEST_TYPED_TEST_CASE(StringSplitLvalueCovertToInt, ::iutest::Types); +IUTEST_TYPED_TEST(StringSplitLvalueCovertToInt, BySingeChar) +{ + using char_type = TypeParam; + const std::basic_string s = constant::csv_data_123_421_113(); + constexpr std::array re1{ { 123, 421, 113 } }; + const auto re2 = s | split(constant::comma()) >> [](const std::basic_string& s) { + return std::stoi(s); + }; + IUTEST_ASSERT_TRUE(std::equal(re1.begin(), re1.end(), re2.begin(), re2.end())); +} +IUTEST_TYPED_TEST(StringSplitLvalueCovertToInt, ByCStr) +{ + using char_type = TypeParam; + const std::basic_string s = constant::csv_data_123_421_113_with_space(); + constexpr std::array re1{ { 123, 421, 113 } }; + const auto re2 = s | split(constant::space_comma()) >> [](const std::basic_string& s) { + return std::stoi(s); + }; + IUTEST_ASSERT_TRUE(std::equal(re1.begin(), re1.end(), re2.begin(), re2.end())); +} +IUTEST_TYPED_TEST(StringSplitLvalueCovertToInt, ByStlStr) +{ + using char_type = TypeParam; + const std::basic_string s = constant::csv_data_123_421_113_with_space(); + constexpr std::array re1{ { 123, 421, 113 } }; + const auto re2 = s | split(std::basic_string(constant::space_comma())) >> [](const std::basic_string& s) { + return std::stoi(s); + }; + IUTEST_ASSERT_TRUE(std::equal(re1.begin(), re1.end(), re2.begin(), re2.end())); +} +#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW +IUTEST_TYPED_TEST(StringSplitLvalueCovertToInt, ByStlStrView) +{ + using char_type = TypeParam; + const std::basic_string s = constant::csv_data_123_421_113_with_space(); + constexpr std::array re1{ { 123, 421, 113 } }; + const auto re2 = s | split(std::basic_string_view(constant::space_comma())) >> [](const std::basic_string& s) { + return std::stoi(s); + }; + IUTEST_ASSERT_TRUE(std::equal(re1.begin(), re1.end(), re2.begin(), re2.end())); +} +#endif +IUTEST_TYPED_TEST(StringSplitLvalueCovertToInt, NoReturnBySingeChar) +{ + using char_type = TypeParam; + const std::basic_string s = constant::csv_data_123_421_113(); + constexpr std::array re1{ { 123, 421, 113 } }; + std::vector re2; + re2.reserve(3); + s | split(constant::comma()) >> [&re2](const std::basic_string& s) { + return re2.push_back(std::stoi(s)); + }; + IUTEST_ASSERT_TRUE(std::equal(re1.begin(), re1.end(), re2.begin(), re2.end())); +} +IUTEST_TYPED_TEST(StringSplitLvalueCovertToInt, NoReturnByCStr) +{ + using char_type = TypeParam; + const std::basic_string s = constant::csv_data_123_421_113_with_space(); + constexpr std::array re1{ { 123, 421, 113 } }; + std::vector re2; + re2.reserve(3); + s | split(constant::space_comma()) >> [&re2](const std::basic_string& s) { + return re2.push_back(std::stoi(s)); + }; + IUTEST_ASSERT_TRUE(std::equal(re1.begin(), re1.end(), re2.begin(), re2.end())); +} +IUTEST_TYPED_TEST(StringSplitLvalueCovertToInt, NoReturnByStlStr) +{ + using char_type = TypeParam; + const std::basic_string s = constant::csv_data_123_421_113_with_space(); + constexpr std::array re1{ { 123, 421, 113 } }; + std::vector re2; + re2.reserve(3); + s | split(std::basic_string(constant::space_comma())) >> [&re2](const std::basic_string& s) { + return re2.push_back(std::stoi(s)); + }; + IUTEST_ASSERT_TRUE(std::equal(re1.begin(), re1.end(), re2.begin(), re2.end())); +} +#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW +IUTEST_TYPED_TEST(StringSplitLvalueCovertToInt, NoReturnByStlStrView) +{ + using char_type = TypeParam; + const std::basic_string s = constant::csv_data_123_421_113_with_space(); + constexpr std::array re1{ { 123, 421, 113 } }; + std::vector re2; + re2.reserve(3); + s | split(std::basic_string_view(constant::space_comma())) >> [&re2](const std::basic_string& s) { + return re2.push_back(std::stoi(s)); + }; + IUTEST_ASSERT_TRUE(std::equal(re1.begin(), re1.end(), re2.begin(), re2.end())); +} +#endif diff --git a/test/test_rvalue.cpp b/test/test_rvalue.cpp new file mode 100644 index 0000000..3b19df6 --- /dev/null +++ b/test/test_rvalue.cpp @@ -0,0 +1,388 @@ +/*============================================================================= + Copyright (C) 2016 yumetodo + + Distributed under the Boost Software License, Version 1.0. + (See http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#include "../include/string_split.hpp" +#include "../iutest/include/iutest.hpp" +#include "constant.hpp" +#include +#include +#include +template +struct StringSplitRvalue : public ::iutest::Test {}; +IUTEST_TYPED_TEST_CASE(StringSplitRvalue, ::iutest::Types); +IUTEST_TYPED_TEST(StringSplitRvalue, chain_front_by_singe_char) +{ + using char_type = TypeParam; + using s = std::basic_string; + const auto re = s(constant::cpp_basic_istream()) | split(constant::space()) >> front(); + IUTEST_ASSERT_EQ(constant::cpp_basic_istream_part(), re); +} +IUTEST_TYPED_TEST(StringSplitRvalue, chain_front_by_c_str) +{ + using char_type = TypeParam; + using s = std::basic_string; + constexpr auto delim = constant::space_underscore(); + const auto re = s(constant::arikitari_na_world_underscore()) | split(delim) >> front(); + IUTEST_ASSERT_EQ(constant::arikitari(), re); +} +IUTEST_TYPED_TEST(StringSplitRvalue, chain_front_by_stl_str) +{ + using char_type = TypeParam; + using s = std::basic_string; + const s delim = constant::space_underscore(); + const auto re = s(constant::arikitari_na_world_underscore()) | split(delim) >> front(); + IUTEST_ASSERT_EQ(constant::arikitari(), re); +} +#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW +IUTEST_TYPED_TEST(StringSplitRvalue, chain_front_by_stl_str_view) +{ + using char_type = TypeParam; + using s = std::basic_string; + const std::basic_string_view delim = constant::space_underscore(); + const auto re = s(constant::arikitari_na_world_underscore()) | split(delim) >> front(); + IUTEST_ASSERT_EQ(constant::arikitari(), re); +} +#endif +IUTEST_TYPED_TEST(StringSplitRvalue, chain_back_by_singe_char) +{ + using char_type = TypeParam; + using s = std::basic_string; + const auto re = s(constant::arikitari_na_world()) | split(constant::space()) >> back(); + IUTEST_ASSERT_EQ(constant::world(), re); +} +IUTEST_TYPED_TEST(StringSplitRvalue, chain_back_by_c_str) +{ + using char_type = TypeParam; + using s = std::basic_string; + constexpr auto delim = constant::space_underscore(); + const auto re = s(constant::arikitari_na_world_underscore()) | split(delim) >> back(); + IUTEST_ASSERT_EQ(constant::world(), re); +} +IUTEST_TYPED_TEST(StringSplitRvalue, chain_back_by_stl_str) +{ + using char_type = TypeParam; + using s = std::basic_string; + const s delim = constant::space_underscore(); + const auto re = s(constant::arikitari_na_world_underscore()) | split(delim) >> back(); + IUTEST_ASSERT_EQ(constant::world(), re); +} +#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW +IUTEST_TYPED_TEST(StringSplitRvalue, chain_back_by_stl_str_view) +{ + using char_type = TypeParam; + using s = std::basic_string; + const std::basic_string_view delim = constant::space_underscore(); + const auto re = s(constant::arikitari_na_world_underscore()) | split(delim) >> back(); + IUTEST_ASSERT_EQ(constant::world(), re); +} +#endif +IUTEST_TYPED_TEST(StringSplitRvalue, chain_at_first_front) +{ + using char_type = TypeParam; + using s = std::basic_string; + const auto re = s(constant::cpp_type_data2()) | split(constant::space()) >> at_first().front(); + IUTEST_ASSERT_EQ(constant::cpp_dxle_sound_c(), re); +} +IUTEST_TYPED_TEST(StringSplitRvalue, chain_at_first_back_by_single_char) +{ + using char_type = TypeParam; + using s = std::basic_string; + const auto re = s(constant::cpp_type_data2()) | split(constant::space()) >> at_first().back(); + IUTEST_ASSERT_EQ(constant::cpp_LoadSoundMem(), re); +} +IUTEST_TYPED_TEST(StringSplitRvalue, chain_at_first_back_by_c_str) +{ + using char_type = TypeParam; + using s = std::basic_string; + const auto re = s(constant::arikitari_na_world_underscore()) + | split(constant::space_underscore()) >> at_first().back(); + IUTEST_ASSERT_EQ(constant::na_world(), re); +} +IUTEST_TYPED_TEST(StringSplitRvalue, chain_at_first_back_by_stl_str) +{ + using char_type = TypeParam; + using s = std::basic_string; + const auto re = s(constant::arikitari_na_world_underscore()) + | split(s(constant::space_underscore())) >> at_first().back(); + IUTEST_ASSERT_EQ(constant::na_world(), re); +} +IUTEST_TYPED_TEST(StringSplitRvalue, chain_at_first_by_single_char) +{ + using char_type = TypeParam; + using s = std::basic_string; + const auto re = s(constant::cpp_type_data2()) | split(constant::space()) >> at_first(); + IUTEST_ASSERT(2u == re.size()); + IUTEST_ASSERT_EQ(constant::cpp_dxle_sound_c(), re[0]); + IUTEST_ASSERT_EQ(constant::cpp_LoadSoundMem(), re[1]); +} +IUTEST_TYPED_TEST(StringSplitRvalue, chain_at_first_by_c_str) +{ + using char_type = TypeParam; + using s = std::basic_string; + const auto re = s(constant::arikitari_na_world_underscore()) | split(constant::space_underscore()) >> at_first(); + IUTEST_ASSERT(2u == re.size()); + IUTEST_ASSERT_EQ(constant::arikitari(), re[0]); + IUTEST_ASSERT_EQ(constant::na_world(), re[1]); +} +IUTEST_TYPED_TEST(StringSplitRvalue, chain_at_first_by_stl_str) +{ + using char_type = TypeParam; + using s = std::basic_string; + const auto re = s(constant::arikitari_na_world_underscore()) | split(s(constant::space_underscore())) >> at_first(); + IUTEST_ASSERT(2u == re.size()); + IUTEST_ASSERT_EQ(constant::arikitari(), re[0]); + IUTEST_ASSERT_EQ(constant::na_world(), re[1]); +} +IUTEST_TYPED_TEST(StringSplitRvalue, chain_at_last_front_by_single_char) +{ + using char_type = TypeParam; + using s = std::basic_string; + const auto re = s(constant::cpp_type_data1()) | split(constant::colon()) >> at_last().front(); + IUTEST_ASSERT_EQ(constant::cpp_basic_istream(), re); +} +IUTEST_TYPED_TEST(StringSplitRvalue, chain_at_last_front_by_c_str) +{ + using char_type = TypeParam; + using s = std::basic_string; + const auto re = s(constant::arikitari_na_world_underscore()) + | split(constant::space_underscore()) >> at_last().front(); + IUTEST_ASSERT_EQ(constant::arikitari_na(), re); +} +IUTEST_TYPED_TEST(StringSplitRvalue, chain_at_last_front_by_stl_str) +{ + using char_type = TypeParam; + using s = std::basic_string; + const auto re = s(constant::arikitari_na_world_underscore()) + | split(s(constant::space_underscore())) >> at_last().front(); + IUTEST_ASSERT_EQ(constant::arikitari_na(), re); +} +IUTEST_TYPED_TEST(StringSplitRvalue, chain_at_last_back) +{ + using char_type = TypeParam; + using s = std::basic_string; + const auto re = s(constant::cpp_type_data1()) | split(constant::colon()) >> at_last().back(); + IUTEST_ASSERT_EQ(constant::ignore(), re); +} +IUTEST_TYPED_TEST(StringSplitRvalue, chain_at_last_by_single_char) +{ + using char_type = TypeParam; + using s = std::basic_string; + const auto re = s(constant::cpp_type_data1()) | split(constant::colon()) >> at_last(); + IUTEST_ASSERT(2u == re.size()); + IUTEST_ASSERT_EQ(constant::cpp_basic_istream(), re[0]); + IUTEST_ASSERT_EQ(constant::ignore(), re[1]); +} +IUTEST_TYPED_TEST(StringSplitRvalue, chain_at_last_by_c_str) +{ + using char_type = TypeParam; + using s = std::basic_string; + const auto re = s(constant::arikitari_na_world_underscore()) | split(constant::space_underscore()) >> at_last(); + IUTEST_ASSERT(2u == re.size()); + IUTEST_ASSERT_EQ(constant::arikitari_na(), re[0]); + IUTEST_ASSERT_EQ(constant::world(), re[1]); +} +IUTEST_TYPED_TEST(StringSplitRvalue, chain_at_last_by_stl_str) +{ + using char_type = TypeParam; + using s = std::basic_string; + const auto re = s(constant::arikitari_na_world_underscore()) | split(s(constant::space_underscore())) >> at_last(); + IUTEST_ASSERT(2u == re.size()); + IUTEST_ASSERT_EQ(constant::arikitari_na(), re[0]); + IUTEST_ASSERT_EQ(constant::world(), re[1]); +} +IUTEST_TYPED_TEST(StringSplitRvalue, ExtractBySingeChar) +{ + using char_type = TypeParam; + using s = std::basic_string; + using lim = std::numeric_limits; + constexpr char_type space = constant::space(); + IUTEST_ASSERT_EQ(constant::arikitari(), s(constant::arikitari_na_world()) | split(space)[0]); + IUTEST_ASSERT_EQ(constant::na(), s(constant::arikitari_na_world()) | split(space)[1]); + IUTEST_ASSERT_EQ(constant::world(), s(constant::arikitari_na_world()) | split(space)[2]); + IUTEST_EXPECT_THROW(s(constant::arikitari_na_world()) | split(space)[3], std::out_of_range); + IUTEST_EXPECT_THROW(s(constant::arikitari_na_world()) | split(space)[5], std::out_of_range); + IUTEST_EXPECT_THROW(s(constant::arikitari_na_world()) | split(space)[3250], std::out_of_range); + IUTEST_EXPECT_THROW(s(constant::arikitari_na_world()) | split(space)[lim::max()], std::out_of_range); +} +IUTEST_TYPED_TEST(StringSplitRvalue, ExtractByCStr) +{ + using char_type = TypeParam; + using s = std::basic_string; + using lim = std::numeric_limits; + const auto delim = constant::space_underscore(); + IUTEST_ASSERT_EQ(constant::arikitari(), s(constant::arikitari_na_world_underscore()) | split(delim)[0]); + IUTEST_ASSERT_EQ(constant::na(), s(constant::arikitari_na_world_underscore()) | split(delim)[1]); + IUTEST_ASSERT_EQ(constant::world(), s(constant::arikitari_na_world_underscore()) | split(delim)[2]); + IUTEST_EXPECT_THROW(s(constant::arikitari_na_world_underscore()) | split(delim)[3], std::out_of_range); + IUTEST_EXPECT_THROW(s(constant::arikitari_na_world_underscore()) | split(delim)[5], std::out_of_range); + IUTEST_EXPECT_THROW(s(constant::arikitari_na_world_underscore()) | split(delim)[3250], std::out_of_range); + IUTEST_EXPECT_THROW(s(constant::arikitari_na_world_underscore()) | split(delim)[lim::max()], std::out_of_range); +} +IUTEST_TYPED_TEST(StringSplitRvalue, ExtractByStlStr) +{ + using char_type = TypeParam; + using s = std::basic_string; + using lim = std::numeric_limits; + const s delim = constant::space_underscore(); + IUTEST_ASSERT_EQ(constant::arikitari(), s(constant::arikitari_na_world_underscore()) | split(delim)[0]); + IUTEST_ASSERT_EQ(constant::na(), s(constant::arikitari_na_world_underscore()) | split(delim)[1]); + IUTEST_ASSERT_EQ(constant::world(), s(constant::arikitari_na_world_underscore()) | split(delim)[2]); + IUTEST_EXPECT_THROW(s(constant::arikitari_na_world_underscore()) | split(delim)[3], std::out_of_range); + IUTEST_EXPECT_THROW(s(constant::arikitari_na_world_underscore()) | split(delim)[5], std::out_of_range); + IUTEST_EXPECT_THROW(s(constant::arikitari_na_world_underscore()) | split(delim)[3250], std::out_of_range); + IUTEST_EXPECT_THROW(s(constant::arikitari_na_world_underscore()) | split(delim)[lim::max()], std::out_of_range); +} +#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW +IUTEST_TYPED_TEST(StringSplitRvalue, ExtractByStlStrView) +{ + using char_type = TypeParam; + using s = std::basic_string; + using lim = std::numeric_limits; + const std::basic_string_view delim = constant::space_underscore(); + IUTEST_ASSERT_EQ(constant::arikitari(), s(constant::arikitari_na_world_underscore()) | split(delim)[0]); + IUTEST_ASSERT_EQ(constant::na(), s(constant::arikitari_na_world_underscore()) | split(delim)[1]); + IUTEST_ASSERT_EQ(constant::world(), s(constant::arikitari_na_world_underscore()) | split(delim)[2]); + IUTEST_EXPECT_THROW(s(constant::arikitari_na_world_underscore()) | split(delim)[3], std::out_of_range); + IUTEST_EXPECT_THROW(s(constant::arikitari_na_world_underscore()) | split(delim)[5], std::out_of_range); + IUTEST_EXPECT_THROW(s(constant::arikitari_na_world_underscore()) | split(delim)[3250], std::out_of_range); + IUTEST_EXPECT_THROW(s(constant::arikitari_na_world_underscore()) | split(delim)[lim::max()], std::out_of_range); +} +#endif +namespace StringSplitRvalue_SplitBySingeChar { + template::value, std::nullptr_t> = nullptr> + void without_char() + { + using char_type = CharType; + using s = std::basic_string; + const s re2_1[] = { constant::arikitarina(), constant::sekai() }; + const auto re2_2 = s(constant::arikitarina_sekai()) | split(constant::space()); + IUTEST_ASSERT_TRUE(std::equal(std::begin(re2_1), std::end(re2_1), re2_2.begin(), re2_2.end())); + } + template::value, std::nullptr_t> = nullptr> + void without_char() {} +} +IUTEST_TYPED_TEST(StringSplitRvalue, SplitBySingeChar) +{ + using char_type = TypeParam; + using s = std::basic_string; + const s re1_1[] = { constant::arikitari(), constant::na(), constant::world() }; + const auto re1_2 = s(constant::arikitari_na_world()) | split(constant::space()); + IUTEST_ASSERT_TRUE(std::equal(std::begin(re1_1), std::end(re1_1), re1_2.begin(), re1_2.end())); + StringSplitRvalue_SplitBySingeChar::without_char(); +} +namespace StringSplitRvalue_SplitByCStr { + template::value, std::nullptr_t> = nullptr> + void without_char() + { + using char_type = CharType; + using s = std::basic_string; + const s re2_1[] = { constant::arikitarina(), constant::sekai() }; + const auto re2_2 = s(constant::arikitarina_sekai_wspace()) | split(constant::wspace()); + IUTEST_ASSERT_TRUE(std::equal(std::begin(re2_1), std::end(re2_1), re2_2.begin(), re2_2.end())); + } + template::value, std::nullptr_t> = nullptr> + void without_char() {} +} +IUTEST_TYPED_TEST(StringSplitRvalue, SplitByCStr) +{ + using char_type = TypeParam; + using s = std::basic_string; + const s re1_1[] = { constant::arikitari(), constant::na(), constant::world() }; + const auto re1_2 = s(constant::arikitari_na_world_underscore()) | split(constant::space_underscore()); + IUTEST_ASSERT_TRUE(std::equal(std::begin(re1_1), std::end(re1_1), re1_2.begin(), re1_2.end())); + StringSplitRvalue_SplitByCStr::without_char(); +} +namespace StringSplitRvalue_SplitByStlStr{ + template::value, std::nullptr_t> = nullptr> + void without_char() + { + using char_type = CharType; + using s = std::basic_string; + const s re2_1[] = { constant::arikitarina(), constant::sekai() }; + const auto re2_2 = s(constant::arikitarina_sekai_wspace()) | split(s(constant::wspace())); + IUTEST_ASSERT_TRUE(std::equal(std::begin(re2_1), std::end(re2_1), re2_2.begin(), re2_2.end())); + } + template::value, std::nullptr_t> = nullptr> + void without_char() {} +} +IUTEST_TYPED_TEST(StringSplitRvalue, SplitByStlStr) +{ + using char_type = TypeParam; + using s = std::basic_string; + const s re1_1[] = { constant::arikitari(), constant::na(), constant::world() }; + const auto re1_2 = s(constant::arikitari_na_world_underscore()) | split(s(constant::space_underscore())); + IUTEST_ASSERT_TRUE(std::equal(std::begin(re1_1), std::end(re1_1), re1_2.begin(), re1_2.end())); + StringSplitRvalue_SplitByStlStr::without_char(); +} +template +struct StringSplitRvalueCovertToInt : public ::iutest::Test {}; +IUTEST_TYPED_TEST_CASE(StringSplitRvalueCovertToInt, ::iutest::Types); +IUTEST_TYPED_TEST(StringSplitRvalueCovertToInt, BySingeChar) +{ + using char_type = TypeParam; + using s = std::basic_string; + constexpr std::array re1{ { 123, 421, 113 } }; + const auto re2 = s(constant::csv_data_123_421_113()) | split(constant::comma()) >> [](const s& s) { + return std::stoi(s); + }; + IUTEST_ASSERT_TRUE(std::equal(re1.begin(), re1.end(), re2.begin(), re2.end())); +} +IUTEST_TYPED_TEST(StringSplitRvalueCovertToInt, ByCStr) +{ + using char_type = TypeParam; + using s = std::basic_string; + constexpr std::array re1{ { 123, 421, 113 } }; + const auto re2 = s(constant::csv_data_123_421_113_with_space()) | split(constant::space_comma()) >> [](const s& s) { + return std::stoi(s); + }; + IUTEST_ASSERT_TRUE(std::equal(re1.begin(), re1.end(), re2.begin(), re2.end())); +} +IUTEST_TYPED_TEST(StringSplitRvalueCovertToInt, ByStlStr) +{ + using char_type = TypeParam; + using s = std::basic_string; + constexpr std::array re1{ { 123, 421, 113 } }; + const auto re2 = s(constant::csv_data_123_421_113_with_space()) | split(s(constant::space_comma())) >> [](const s& s) { + return std::stoi(s); + }; + IUTEST_ASSERT_TRUE(std::equal(re1.begin(), re1.end(), re2.begin(), re2.end())); +} +IUTEST_TYPED_TEST(StringSplitRvalueCovertToInt, NoReturnBySingeChar) +{ + using char_type = TypeParam; + using s = std::basic_string; + constexpr std::array re1{ { 123, 421, 113 } }; + std::vector re2; + re2.reserve(3); + s(constant::csv_data_123_421_113()) | split(constant::comma()) >> [&re2](const s& s) { + re2.push_back(std::stoi(s)); + }; + IUTEST_ASSERT_TRUE(std::equal(re1.begin(), re1.end(), re2.begin(), re2.end())); +} +IUTEST_TYPED_TEST(StringSplitRvalueCovertToInt, NoReturnByCStr) +{ + using char_type = TypeParam; + using s = std::basic_string; + constexpr std::array re1{ { 123, 421, 113 } }; + std::vector re2; + re2.reserve(3); + s(constant::csv_data_123_421_113_with_space()) | split(constant::space_comma()) >> [&re2](const s& s) { + re2.push_back(std::stoi(s)); + }; + IUTEST_ASSERT_TRUE(std::equal(re1.begin(), re1.end(), re2.begin(), re2.end())); +} +IUTEST_TYPED_TEST(StringSplitRvalueCovertToInt, NoReturnByStlStr) +{ + using char_type = TypeParam; + using s = std::basic_string; + constexpr std::array re1{ { 123, 421, 113 } }; + std::vector re2; + re2.reserve(3); + s(constant::csv_data_123_421_113_with_space()) | split(s(constant::space_comma())) >> [&re2](const s& s) { + re2.push_back(std::stoi(s)); + }; + IUTEST_ASSERT_TRUE(std::equal(re1.begin(), re1.end(), re2.begin(), re2.end())); +} From dbde7ef136d312ef3bf58b4201750aa7b309586e Mon Sep 17 00:00:00 2001 From: yumetodo Date: Sat, 14 Jul 2018 17:25:38 +0900 Subject: [PATCH 65/68] fix: remove un-maintained Makefile and vs project use cmake to generate that --- Makefile | 17 -- benchmark/Makefile | 42 ----- benchmark/benchmark.vcxproj | 238 -------------------------- benchmark/benchmark.vcxproj.filters | 30 ---- sample/Makefile | 42 ----- sample/sample.vcxproj | 237 ------------------------- sample/sample.vcxproj.filters | 22 --- string_split.sln | 76 --------- test/Makefile | 77 --------- test/test.vcxproj | 256 ---------------------------- test/test.vcxproj.filters | 30 ---- 11 files changed, 1067 deletions(-) delete mode 100644 Makefile delete mode 100644 benchmark/Makefile delete mode 100644 benchmark/benchmark.vcxproj delete mode 100644 benchmark/benchmark.vcxproj.filters delete mode 100644 sample/Makefile delete mode 100644 sample/sample.vcxproj delete mode 100644 sample/sample.vcxproj.filters delete mode 100644 string_split.sln delete mode 100644 test/Makefile delete mode 100644 test/test.vcxproj delete mode 100644 test/test.vcxproj.filters diff --git a/Makefile b/Makefile deleted file mode 100644 index 0d9be42..0000000 --- a/Makefile +++ /dev/null @@ -1,17 +0,0 @@ -.PHONY: Debug -Debug: - $(CXX) --version - cd test; $(MAKE) Debug - cd sample; $(MAKE) Debug - cd benchmark; $(MAKE) Debug -.PHONY: Release -Release: - $(CXX) --version - cd test; $(MAKE) Release - cd sample; $(MAKE) Release - cd benchmark; $(MAKE) Release -.PHONY: clean -clean: - cd test; $(MAKE) clean - cd sample; $(MAKE) clean - cd benchmark; $(MAKE) clean diff --git a/benchmark/Makefile b/benchmark/Makefile deleted file mode 100644 index 18453ca..0000000 --- a/benchmark/Makefile +++ /dev/null @@ -1,42 +0,0 @@ -# Makefile for benchmark.out - -TARGET = benchmark.out -SRCS = ./benchmark.cpp - -# 基本コマンド -RM ?= rm -CXX ?= g++ -CC ?= gcc - -# デバッグ時とリリース時の微調整 -CXX_DEBUG_FLAGS = -g -O0 -Wall -Wextra -CXX_RELEASE_FLAGS = -O2 -Wall -Wextra - -# 基本オプション -CPPFLAGS = -std=c++14 -Wunused -CONFIGURATION = unknown -PLATFORM = $(shell uname) - -# make -# debug -.PHONY: Debug -Debug: CXXFLAGS+=$(CXX_DEBUG_FLAGS) -Debug: CONFIGURATION=Debug -Debug: all -# release -.PHONY: Release -Release: CXXFLAGS+=$(CXX_RELEASE_FLAGS) -Release: CONFIGURATION=Release -Release: all - -.PHONY: all -all: $(TARGET) -$(TARGET): $(SRCS) - $(CXX) --version - $(CXX) $^ -o $@ $(CXXFLAGS) $(CPPFLAGS) - mkdir -p bin/$(CXX)/$(PLATFORM)/$(CONFIGURATION) && cp $(TARGET) bin/$(CXX)/$(PLATFORM)/$(CONFIGURATION)/$(TARGET) - -# make clean -.PHONY: clean -clean: - $(RM) -f *.out diff --git a/benchmark/benchmark.vcxproj b/benchmark/benchmark.vcxproj deleted file mode 100644 index 1f92056..0000000 --- a/benchmark/benchmark.vcxproj +++ /dev/null @@ -1,238 +0,0 @@ - - - - - clang_Debug - Win32 - - - clang_Debug - x64 - - - clang_Release - Win32 - - - clang_Release - x64 - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - {C964C9F8-FE0B-4837-9160-89966C8A4E52} - Win32Proj - benchmark - 8.1 - - - - Application - true - v141 - Unicode - - - Application - false - v141 - true - Unicode - - - Application - true - v141 - Unicode - - - Application - false - v141 - true - Unicode - - - v141_clang_3_7 - - - v141_Clang_3_7 - - - v141_clang_3_7 - - - v141_Clang_3_7 - - - - - - - - - - - - - - - - - - - - - true - bin\$(Platform)\$(Configuration)\ - tmp\$(Platform)\$(Configuration)\ - - - true - bin\$(Platform)\$(Configuration)\ - tmp\$(Platform)\$(Configuration)\ - - - false - bin\$(Platform)\$(Configuration)\ - tmp\$(Platform)\$(Configuration)\ - - - false - bin\$(Platform)\$(Configuration)\ - tmp\$(Platform)\$(Configuration)\ - - - bin\$(Platform)\$(Configuration)\ - tmp\$(Platform)\$(Configuration)\ - - - bin\$(Platform)\$(Configuration)\ - tmp\$(Platform)\$(Configuration)\ - - - bin\$(Platform)\$(Configuration)\ - tmp\$(Platform)\$(Configuration)\ - - - bin\$(Platform)\$(Configuration)\ - tmp\$(Platform)\$(Configuration)\ - - - - - - Level3 - Disabled - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - 5030 - - - Console - true - - - - - - - Level3 - Disabled - _DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - 5030 - - - Console - true - - - - - Level3 - - - MaxSpeed - true - true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - 5030 - - - Console - true - true - true - - - - - Level3 - - - MaxSpeed - true - true - NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - 5030 - - - Console - true - true - true - - - - - Enabled - - - - - Enabled - Disabled - FullDebug - - - - - Enabled - - - - - Enabled - Disabled - FullDebug - - - - - - - - - - - - - \ No newline at end of file diff --git a/benchmark/benchmark.vcxproj.filters b/benchmark/benchmark.vcxproj.filters deleted file mode 100644 index 2717eeb..0000000 --- a/benchmark/benchmark.vcxproj.filters +++ /dev/null @@ -1,30 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - ソース ファイル - - - - - ヘッダー ファイル - - - ヘッダー ファイル - - - \ No newline at end of file diff --git a/sample/Makefile b/sample/Makefile deleted file mode 100644 index 9724300..0000000 --- a/sample/Makefile +++ /dev/null @@ -1,42 +0,0 @@ -# Makefile for sample.out - -TARGET = sample.out -SRCS = ./sample.cpp - -# 基本コマンド -RM ?= rm -CXX ?= g++ -CC ?= gcc - -# デバッグ時とリリース時の微調整 -CXX_DEBUG_FLAGS = -g -O0 -Wall -Wextra -CXX_RELEASE_FLAGS = -O2 -Wall -Wextra - -# 基本オプション -CPPFLAGS = -std=c++11 -CONFIGURATION = unknown -PLATFORM = $(shell uname) - -# make -# debug -.PHONY: Debug -Debug: CXXFLAGS+=$(CXX_DEBUG_FLAGS) -Debug: CONFIGURATION=Debug -Debug: all -# release -.PHONY: Release -Release: CXXFLAGS+=$(CXX_RELEASE_FLAGS) -Release: CONFIGURATION=Release -Release: all - -.PHONY: all -all: $(TARGET) -$(TARGET): $(SRCS) - $(CXX) --version - $(CXX) $^ -o $@ $(CXXFLAGS) $(CPPFLAGS) - mkdir -p bin/$(CXX)/$(PLATFORM)/$(CONFIGURATION) && cp $(TARGET) bin/$(CXX)/$(PLATFORM)/$(CONFIGURATION)/$(TARGET) - -# make clean -.PHONY: clean -clean: - $(RM) -f *.out diff --git a/sample/sample.vcxproj b/sample/sample.vcxproj deleted file mode 100644 index f62d719..0000000 --- a/sample/sample.vcxproj +++ /dev/null @@ -1,237 +0,0 @@ - - - - - clang_Debug - Win32 - - - clang_Debug - x64 - - - clang_Release - Win32 - - - clang_Release - x64 - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - {7BF2E472-65F2-4A67-8B00-02A0AE976C56} - Win32Proj - string_split - 8.1 - sample - - - - Application - true - v141 - Unicode - - - Application - false - v141 - true - Unicode - - - Application - true - v141 - Unicode - - - Application - false - v141 - true - Unicode - - - v141_clang_3_7 - - - v141_Clang_3_7 - - - v141_clang_3_7 - - - v141_Clang_3_7 - - - - - - - - - - - - - - - - - - - - - true - tmp\$(Platform)\$(Configuration)\ - bin\$(Platform)\$(Configuration)\ - - - true - tmp\$(Platform)\$(Configuration)\ - bin\$(Platform)\$(Configuration)\ - - - false - tmp\$(Platform)\$(Configuration)\ - bin\$(Platform)\$(Configuration)\ - - - false - tmp\$(Platform)\$(Configuration)\ - bin\$(Platform)\$(Configuration)\ - - - tmp\$(Platform)\$(Configuration)\ - bin\$(Platform)\$(Configuration)\ - - - tmp\$(Platform)\$(Configuration)\ - bin\$(Platform)\$(Configuration)\ - - - tmp\$(Platform)\$(Configuration)\ - bin\$(Platform)\$(Configuration)\ - - - tmp\$(Platform)\$(Configuration)\ - bin\$(Platform)\$(Configuration)\ - - - - - - Level3 - Disabled - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - ../include - - - Console - true - - - - - - - Level3 - Disabled - _DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - ../include - - - Console - true - - - - - Level3 - - - MaxSpeed - true - true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - ../include - - - Console - true - true - true - - - - - Level3 - - - MaxSpeed - true - true - NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - ../include - - - Console - true - true - true - - - - - Enabled - ../include - - - - - Enabled - Disabled - ../include - - - - - Enabled - ../include - - - - - Enabled - Disabled - ../include - - - - - - - - - \ No newline at end of file diff --git a/sample/sample.vcxproj.filters b/sample/sample.vcxproj.filters deleted file mode 100644 index a3c23eb..0000000 --- a/sample/sample.vcxproj.filters +++ /dev/null @@ -1,22 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - ソース ファイル - - - \ No newline at end of file diff --git a/string_split.sln b/string_split.sln deleted file mode 100644 index 413ac3c..0000000 --- a/string_split.sln +++ /dev/null @@ -1,76 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.25420.1 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sample", "sample\sample.vcxproj", "{7BF2E472-65F2-4A67-8B00-02A0AE976C56}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test", "test\test.vcxproj", "{F9C51F52-6771-46C2-AEA3-910A656FA13E}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "benchmark", "benchmark\benchmark.vcxproj", "{C964C9F8-FE0B-4837-9160-89966C8A4E52}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - clang_Debug|x64 = clang_Debug|x64 - clang_Debug|x86 = clang_Debug|x86 - clang_Release|x64 = clang_Release|x64 - clang_Release|x86 = clang_Release|x86 - Debug|x64 = Debug|x64 - Debug|x86 = Debug|x86 - Release|x64 = Release|x64 - Release|x86 = Release|x86 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {7BF2E472-65F2-4A67-8B00-02A0AE976C56}.clang_Debug|x64.ActiveCfg = clang_Debug|x64 - {7BF2E472-65F2-4A67-8B00-02A0AE976C56}.clang_Debug|x64.Build.0 = clang_Debug|x64 - {7BF2E472-65F2-4A67-8B00-02A0AE976C56}.clang_Debug|x86.ActiveCfg = clang_Debug|Win32 - {7BF2E472-65F2-4A67-8B00-02A0AE976C56}.clang_Debug|x86.Build.0 = clang_Debug|Win32 - {7BF2E472-65F2-4A67-8B00-02A0AE976C56}.clang_Release|x64.ActiveCfg = clang_Release|x64 - {7BF2E472-65F2-4A67-8B00-02A0AE976C56}.clang_Release|x64.Build.0 = clang_Release|x64 - {7BF2E472-65F2-4A67-8B00-02A0AE976C56}.clang_Release|x86.ActiveCfg = clang_Release|Win32 - {7BF2E472-65F2-4A67-8B00-02A0AE976C56}.clang_Release|x86.Build.0 = clang_Release|Win32 - {7BF2E472-65F2-4A67-8B00-02A0AE976C56}.Debug|x64.ActiveCfg = Debug|x64 - {7BF2E472-65F2-4A67-8B00-02A0AE976C56}.Debug|x64.Build.0 = Debug|x64 - {7BF2E472-65F2-4A67-8B00-02A0AE976C56}.Debug|x86.ActiveCfg = Debug|Win32 - {7BF2E472-65F2-4A67-8B00-02A0AE976C56}.Debug|x86.Build.0 = Debug|Win32 - {7BF2E472-65F2-4A67-8B00-02A0AE976C56}.Release|x64.ActiveCfg = Release|x64 - {7BF2E472-65F2-4A67-8B00-02A0AE976C56}.Release|x64.Build.0 = Release|x64 - {7BF2E472-65F2-4A67-8B00-02A0AE976C56}.Release|x86.ActiveCfg = Release|Win32 - {7BF2E472-65F2-4A67-8B00-02A0AE976C56}.Release|x86.Build.0 = Release|Win32 - {F9C51F52-6771-46C2-AEA3-910A656FA13E}.clang_Debug|x64.ActiveCfg = clang_Debug|x64 - {F9C51F52-6771-46C2-AEA3-910A656FA13E}.clang_Debug|x64.Build.0 = clang_Debug|x64 - {F9C51F52-6771-46C2-AEA3-910A656FA13E}.clang_Debug|x86.ActiveCfg = clang_Debug|Win32 - {F9C51F52-6771-46C2-AEA3-910A656FA13E}.clang_Debug|x86.Build.0 = clang_Debug|Win32 - {F9C51F52-6771-46C2-AEA3-910A656FA13E}.clang_Release|x64.ActiveCfg = clang_Release|x64 - {F9C51F52-6771-46C2-AEA3-910A656FA13E}.clang_Release|x64.Build.0 = clang_Release|x64 - {F9C51F52-6771-46C2-AEA3-910A656FA13E}.clang_Release|x86.ActiveCfg = clang_Release|Win32 - {F9C51F52-6771-46C2-AEA3-910A656FA13E}.clang_Release|x86.Build.0 = clang_Release|Win32 - {F9C51F52-6771-46C2-AEA3-910A656FA13E}.Debug|x64.ActiveCfg = Debug|x64 - {F9C51F52-6771-46C2-AEA3-910A656FA13E}.Debug|x64.Build.0 = Debug|x64 - {F9C51F52-6771-46C2-AEA3-910A656FA13E}.Debug|x86.ActiveCfg = Debug|Win32 - {F9C51F52-6771-46C2-AEA3-910A656FA13E}.Debug|x86.Build.0 = Debug|Win32 - {F9C51F52-6771-46C2-AEA3-910A656FA13E}.Release|x64.ActiveCfg = Release|x64 - {F9C51F52-6771-46C2-AEA3-910A656FA13E}.Release|x64.Build.0 = Release|x64 - {F9C51F52-6771-46C2-AEA3-910A656FA13E}.Release|x86.ActiveCfg = Release|Win32 - {F9C51F52-6771-46C2-AEA3-910A656FA13E}.Release|x86.Build.0 = Release|Win32 - {C964C9F8-FE0B-4837-9160-89966C8A4E52}.clang_Debug|x64.ActiveCfg = clang_Debug|x64 - {C964C9F8-FE0B-4837-9160-89966C8A4E52}.clang_Debug|x64.Build.0 = clang_Debug|x64 - {C964C9F8-FE0B-4837-9160-89966C8A4E52}.clang_Debug|x86.ActiveCfg = clang_Debug|Win32 - {C964C9F8-FE0B-4837-9160-89966C8A4E52}.clang_Debug|x86.Build.0 = clang_Debug|Win32 - {C964C9F8-FE0B-4837-9160-89966C8A4E52}.clang_Release|x64.ActiveCfg = clang_Release|x64 - {C964C9F8-FE0B-4837-9160-89966C8A4E52}.clang_Release|x64.Build.0 = clang_Release|x64 - {C964C9F8-FE0B-4837-9160-89966C8A4E52}.clang_Release|x86.ActiveCfg = clang_Release|Win32 - {C964C9F8-FE0B-4837-9160-89966C8A4E52}.clang_Release|x86.Build.0 = clang_Release|Win32 - {C964C9F8-FE0B-4837-9160-89966C8A4E52}.Debug|x64.ActiveCfg = Debug|x64 - {C964C9F8-FE0B-4837-9160-89966C8A4E52}.Debug|x64.Build.0 = Debug|x64 - {C964C9F8-FE0B-4837-9160-89966C8A4E52}.Debug|x86.ActiveCfg = Debug|Win32 - {C964C9F8-FE0B-4837-9160-89966C8A4E52}.Debug|x86.Build.0 = Debug|Win32 - {C964C9F8-FE0B-4837-9160-89966C8A4E52}.Release|x64.ActiveCfg = Release|x64 - {C964C9F8-FE0B-4837-9160-89966C8A4E52}.Release|x64.Build.0 = Release|x64 - {C964C9F8-FE0B-4837-9160-89966C8A4E52}.Release|x86.ActiveCfg = Release|Win32 - {C964C9F8-FE0B-4837-9160-89966C8A4E52}.Release|x86.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/test/Makefile b/test/Makefile deleted file mode 100644 index bebfbf1..0000000 --- a/test/Makefile +++ /dev/null @@ -1,77 +0,0 @@ -# Makefile for test.out - -TARGET = test.out -SRCS = ./test.cpp - -# 基本コマンド -RM ?= rm -CXX ?= g++ -CC ?= gcc -CCOV ?= gcov - -# デバッグ時とリリース時の微調整 -CXX_DEBUG_FLAGS = -g -O0 -Wall -Wextra -CXX_RELEASE_FLAGS = -O2 -Wall -Wextra - -# 基本オプション -CPPFLAGS = -std=c++17 -ifeq ($(OS),Windows_NT) -CPPFLAGS += -lWs2_32 -endif - -CONFIGURATION = unknown -PLATFORM = $(shell uname) -COVERAGE_OPTION := -coverage -# make -# debug -.PHONY: Debug -Debug: CXXFLAGS+=$(CXX_DEBUG_FLAGS) -ifdef USE_COVERAGE -Debug: CXXFLAGS+=$(COVERAGE_OPTION) -endif -Debug: CONFIGURATION=Debug -Debug: all -# release -.PHONY: Release -Release: CXXFLAGS+=$(CXX_RELEASE_FLAGS) -Release: CONFIGURATION=Release -Release: all - -.PHONY: all -all: $(TARGET) -$(TARGET): $(SRCS) - $(CXX) --version; - $(CXX) $^ -o $@ $(CXXFLAGS) $(CPPFLAGS) - mkdir -p bin/$(CXX)/$(PLATFORM)/$(CONFIGURATION) && cp $(TARGET) bin/$(CXX)/$(PLATFORM)/$(CONFIGURATION)/$(TARGET) - -# make clean -.PHONY: clean -clean: - $(RM) -f *.out - -# coverage -.PHONY: coverage -coverage: - $(CCOV) -v -ifeq ($(USE_COVERAGE),lcov) - lcov --version - lcov -c -d . --gcov-tool "$(shell which $(CCOV))" -o coverage.info && lcov -r coverage.info *gcc* -o coverage.info && lcov -r coverage.info *iutest* -o coverage.info && lcov -r coverage.info */usr/include/* -o coverage.info && lcov -r coverage.info *mingw* -o coverage.info; -endif -ifeq ($(USE_COVERAGE),gcov) -ifeq ($(findstring relative-only, $(shell $(CCOV) --help)), relative-only) - gcov -r *.gcda; -else - gcov *.gcda; -endif -endif - -# send-coveralls -.PHONY: send-coveralls -send-coveralls: coverage - pwd -ifeq ($(USE_COVERAGE),lcov) - cd ../; lcoveralls --retry-count 3 ./test/coverage.info -endif -ifeq ($(USE_COVERAGE),gcov) - coveralls -n -r ./ -b ./ $(COVARALLS_EXCLUDE_PATTERN) $(COVARALLS_EXCLUDE) -endif \ No newline at end of file diff --git a/test/test.vcxproj b/test/test.vcxproj deleted file mode 100644 index 9c5f202..0000000 --- a/test/test.vcxproj +++ /dev/null @@ -1,256 +0,0 @@ - - - - - clang_Debug - Win32 - - - clang_Debug - x64 - - - clang_Release - Win32 - - - clang_Release - x64 - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - {F9C51F52-6771-46C2-AEA3-910A656FA13E} - Win32Proj - test - 8.1 - - - - Application - true - v141 - Unicode - - - Application - false - v141 - true - Unicode - - - Application - true - v141 - Unicode - - - Application - false - v141 - true - Unicode - - - v141_clang_c2 - - - v141_clang_c2 - - - v141_clang_c2 - - - v141_clang_c2 - - - - - - - - - - - - - - - - - - - - - true - bin\$(Platform)\$(Configuration)\ - tmp\$(Platform)\$(Configuration)\ - - - true - bin\$(Platform)\$(Configuration)\ - tmp\$(Platform)\$(Configuration)\ - - - false - bin\$(Platform)\$(Configuration)\ - tmp\$(Platform)\$(Configuration)\ - - - false - bin\$(Platform)\$(Configuration)\ - tmp\$(Platform)\$(Configuration)\ - - - bin\$(Platform)\$(Configuration)\ - tmp\$(Platform)\$(Configuration)\ - - - bin\$(Platform)\$(Configuration)\ - tmp\$(Platform)\$(Configuration)\ - - - bin\$(Platform)\$(Configuration)\ - tmp\$(Platform)\$(Configuration)\ - - - bin\$(Platform)\$(Configuration)\ - tmp\$(Platform)\$(Configuration)\ - - - - - - Level4 - Disabled - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - ../include - Async - /bigobj %(AdditionalOptions) - stdcpp17 - - - Console - true - - - - - - - Level4 - Disabled - _DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - ../include - Async - /bigobj %(AdditionalOptions) - stdcpp17 - - - Console - true - - - - - Level4 - - - MaxSpeed - true - true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - ../include - Async - /bigobj %(AdditionalOptions) - stdcpp17 - - - Console - true - true - true - - - - - Level4 - - - MaxSpeed - true - true - NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - ../include - Async - /bigobj %(AdditionalOptions) - stdcpp17 - - - Console - true - true - true - - - - - Enabled - ../include - - - - - - Enabled - Disabled - ../include - - - - - - Enabled - ../include - - - - - - Enabled - Disabled - ../include - - - - - - - - - - - - - - \ No newline at end of file diff --git a/test/test.vcxproj.filters b/test/test.vcxproj.filters deleted file mode 100644 index ab4e1be..0000000 --- a/test/test.vcxproj.filters +++ /dev/null @@ -1,30 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - ソース ファイル - - - ソース ファイル - - - - - ヘッダー ファイル - - - \ No newline at end of file From 4ea5cbb4e27f49f306c87805ce50bc91fac378e5 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Sat, 14 Jul 2018 17:51:25 +0900 Subject: [PATCH 66/68] feat(test): add missing string_view version test case --- test/test_rvalue.cpp | 90 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/test/test_rvalue.cpp b/test/test_rvalue.cpp index 3b19df6..a995127 100644 --- a/test/test_rvalue.cpp +++ b/test/test_rvalue.cpp @@ -109,6 +109,17 @@ IUTEST_TYPED_TEST(StringSplitRvalue, chain_at_first_back_by_stl_str) | split(s(constant::space_underscore())) >> at_first().back(); IUTEST_ASSERT_EQ(constant::na_world(), re); } +#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW +IUTEST_TYPED_TEST(StringSplitRvalue, chain_at_first_back_by_stl_str_view) +{ + using char_type = TypeParam; + using s = std::basic_string; + using sw = std::basic_string_view; + const auto re = s(constant::arikitari_na_world_underscore()) + | split(sw(constant::space_underscore())) >> at_first().back(); + IUTEST_ASSERT_EQ(constant::na_world(), re); +} +#endif IUTEST_TYPED_TEST(StringSplitRvalue, chain_at_first_by_single_char) { using char_type = TypeParam; @@ -136,6 +147,18 @@ IUTEST_TYPED_TEST(StringSplitRvalue, chain_at_first_by_stl_str) IUTEST_ASSERT_EQ(constant::arikitari(), re[0]); IUTEST_ASSERT_EQ(constant::na_world(), re[1]); } +#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW +IUTEST_TYPED_TEST(StringSplitRvalue, chain_at_first_by_stl_str_view) +{ + using char_type = TypeParam; + using s = std::basic_string; + using sw = std::basic_string_view; + const auto re = s(constant::arikitari_na_world_underscore()) | split(sw(constant::space_underscore())) >> at_first(); + IUTEST_ASSERT(2u == re.size()); + IUTEST_ASSERT_EQ(constant::arikitari(), re[0]); + IUTEST_ASSERT_EQ(constant::na_world(), re[1]); +} +#endif IUTEST_TYPED_TEST(StringSplitRvalue, chain_at_last_front_by_single_char) { using char_type = TypeParam; @@ -159,6 +182,17 @@ IUTEST_TYPED_TEST(StringSplitRvalue, chain_at_last_front_by_stl_str) | split(s(constant::space_underscore())) >> at_last().front(); IUTEST_ASSERT_EQ(constant::arikitari_na(), re); } +#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW +IUTEST_TYPED_TEST(StringSplitRvalue, chain_at_last_front_by_stl_str_view) +{ + using char_type = TypeParam; + using s = std::basic_string; + using sw = std::basic_string_view; + const auto re = s(constant::arikitari_na_world_underscore()) + | split(sw(constant::space_underscore())) >> at_last().front(); + IUTEST_ASSERT_EQ(constant::arikitari_na(), re); +} +#endif IUTEST_TYPED_TEST(StringSplitRvalue, chain_at_last_back) { using char_type = TypeParam; @@ -193,6 +227,18 @@ IUTEST_TYPED_TEST(StringSplitRvalue, chain_at_last_by_stl_str) IUTEST_ASSERT_EQ(constant::arikitari_na(), re[0]); IUTEST_ASSERT_EQ(constant::world(), re[1]); } +#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW +IUTEST_TYPED_TEST(StringSplitRvalue, chain_at_last_by_stl_str_view) +{ + using char_type = TypeParam; + using s = std::basic_string; + using sw = std::basic_string_view; + const auto re = s(constant::arikitari_na_world_underscore()) | split(sw(constant::space_underscore())) >> at_last(); + IUTEST_ASSERT(2u == re.size()); + IUTEST_ASSERT_EQ(constant::arikitari_na(), re[0]); + IUTEST_ASSERT_EQ(constant::world(), re[1]); +} +#endif IUTEST_TYPED_TEST(StringSplitRvalue, ExtractBySingeChar) { using char_type = TypeParam; @@ -317,6 +363,22 @@ IUTEST_TYPED_TEST(StringSplitRvalue, SplitByStlStr) IUTEST_ASSERT_TRUE(std::equal(std::begin(re1_1), std::end(re1_1), re1_2.begin(), re1_2.end())); StringSplitRvalue_SplitByStlStr::without_char(); } +#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW +IUTEST_TYPED_TEST(StringSplitRvalue, SplitByStlStrView) +{ + using char_type = TypeParam; + using s = std::basic_string; + using sw = std::basic_string_view; + const s re1_1[] = { constant::arikitari(), constant::na(), constant::world() }; + const auto re1_2 = s(constant::arikitari_na_world_underscore()) | split(sw(constant::space_underscore())); + IUTEST_ASSERT_TRUE(std::equal(std::begin(re1_1), std::end(re1_1), re1_2.begin(), re1_2.end())); + if constexpr(!std::is_same_v) { + const s re2_1[] = { constant::arikitarina(), constant::sekai() }; + const auto re2_2 = s(constant::arikitarina_sekai_wspace()) | split(sw(constant::wspace())); + IUTEST_ASSERT_TRUE(std::equal(std::begin(re2_1), std::end(re2_1), re2_2.begin(), re2_2.end())); + } +} +#endif template struct StringSplitRvalueCovertToInt : public ::iutest::Test {}; IUTEST_TYPED_TEST_CASE(StringSplitRvalueCovertToInt, ::iutest::Types); @@ -350,6 +412,19 @@ IUTEST_TYPED_TEST(StringSplitRvalueCovertToInt, ByStlStr) }; IUTEST_ASSERT_TRUE(std::equal(re1.begin(), re1.end(), re2.begin(), re2.end())); } +#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW +IUTEST_TYPED_TEST(StringSplitRvalueCovertToInt, ByStlStrView) +{ + using char_type = TypeParam; + using s = std::basic_string; + using sw = std::basic_string_view; + constexpr std::array re1{ { 123, 421, 113 } }; + const auto re2 = s(constant::csv_data_123_421_113_with_space()) | split(sw(constant::space_comma())) >> [](const s& s) { + return std::stoi(s); + }; + IUTEST_ASSERT_TRUE(std::equal(re1.begin(), re1.end(), re2.begin(), re2.end())); +} +#endif IUTEST_TYPED_TEST(StringSplitRvalueCovertToInt, NoReturnBySingeChar) { using char_type = TypeParam; @@ -386,3 +461,18 @@ IUTEST_TYPED_TEST(StringSplitRvalueCovertToInt, NoReturnByStlStr) }; IUTEST_ASSERT_TRUE(std::equal(re1.begin(), re1.end(), re2.begin(), re2.end())); } +#ifdef STRING_SPLIT_HAS_CXX17_STRING_VIEW +IUTEST_TYPED_TEST(StringSplitRvalueCovertToInt, NoReturnByStlStrView) +{ + using char_type = TypeParam; + using s = std::basic_string; + using sw = std::basic_string_view; + constexpr std::array re1{ { 123, 421, 113 } }; + std::vector re2; + re2.reserve(3); + s(constant::csv_data_123_421_113_with_space()) | split(sw(constant::space_comma())) >> [&re2](const s& s) { + re2.push_back(std::stoi(s)); + }; + IUTEST_ASSERT_TRUE(std::equal(re1.begin(), re1.end(), re2.begin(), re2.end())); +} +#endif From 50cf0364bd925784a68fe2e8641d4dae1d3cd841 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Sat, 14 Jul 2018 17:51:47 +0900 Subject: [PATCH 67/68] fix: update readme --- README.md | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 060ec1e..a2fde57 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ -# string split like chain method +# string split like chain method + [![Run Status](https://api.shippable.com/projects/577cc6213be4f4faa56be97c/badge?branch=master)](https://app.shippable.com/projects/577cc6213be4f4faa56be97c) [![Build Status](https://travis-ci.org/yumetodo/string_split.svg?branch=master)](https://travis-ci.org/yumetodo/string_split) [![Coverage Status](https://coveralls.io/repos/github/yumetodo/string_split/badge.svg?branch=master)](https://coveralls.io/github/yumetodo/string_split?branch=master) @@ -6,9 +7,9 @@ This is a **C++ header only** library to split string. -# Usage +## Usage -just include ``include/string_split.hpp``. +Just include `include/string_split.hpp`. ```cpp #include "../include/string_split.hpp" @@ -33,9 +34,20 @@ int main() } ``` -Temporary ``std::vector`` **will not be created** becase the priority of ``operator[]/operator>>`` is higher than ``operator|`` +Temporary `std::vector` **will not be created** becase the priority of `operator[]/operator>>` is higher than `operator|` + +## Compiler requirement -# Compiler require C++11 support is required(need C++14 support is required to compile testcase). -However, we support Visual Studio 2015 update2 or later. \ No newline at end of file +However, we support Visual Studio 2015 update2 or later. + +### `std::string_view` + +We are supporting `std::basic_string_view`. + +Enable C++17 mode and use below: + +- Visual Studio 2017 +- GCC 7.1 or later +- clang 4 or later From 8dd9bdb4b472a041a3e7086c3b86ace6e1e77858 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Sat, 14 Jul 2018 18:05:44 +0900 Subject: [PATCH 68/68] fix: add missing comma --- include/string_split.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/string_split.hpp b/include/string_split.hpp index c347dde..714e49e 100644 --- a/include/string_split.hpp +++ b/include/string_split.hpp @@ -632,7 +632,7 @@ namespace detail { auto operator| (const b_str& str, const split_helper_conv_func& info) -> enable_if_t< type_traits::conjunction< - type_traits::contract_delim_type_without_single_char + type_traits::contract_delim_type_without_single_char, is_void>> >::value, void