From 6e8f686f72daeb7d83ce7020adc656f765b6c807 Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Tue, 25 Dec 2018 17:11:15 +0900 Subject: [PATCH] temporary workaround for old GCC --- sprout/string/string.hpp | 4 ++ sprout/sub_array/sub.hpp | 18 +++++++ sprout/utility/string_view/string_view.hpp | 10 ++-- .../utility/string_view/string_view_fwd.hpp | 22 ++++++++ sprout/utility/value_holder/value_holder.hpp | 16 +++--- testspr/trace.hpp | 51 +++++++++++++++---- 6 files changed, 101 insertions(+), 20 deletions(-) create mode 100644 sprout/utility/string_view/string_view_fwd.hpp diff --git a/sprout/string/string.hpp b/sprout/string/string.hpp index 21f06abe..ac98b390 100644 --- a/sprout/string/string.hpp +++ b/sprout/string/string.hpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -885,6 +886,9 @@ namespace sprout { SPROUT_EXPLICIT_CONVERSION SPROUT_NON_CONSTEXPR operator std::basic_string() const { return std::basic_string(data(), size()); } + operator sprout::basic_string_view() const SPROUT_NOEXCEPT { + return sprout::basic_string_view(*this); + } SPROUT_CXX14_CONSTEXPR void rangecheck(size_type i) const { return i >= size() ? throw std::out_of_range("basic_string<>: index out of range") diff --git a/sprout/sub_array/sub.hpp b/sprout/sub_array/sub.hpp index 33b04bd5..eefce31d 100644 --- a/sprout/sub_array/sub.hpp +++ b/sprout/sub_array/sub.hpp @@ -137,6 +137,12 @@ namespace sprout { return sprout::sub_window(arr, to_first); } + template + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type + sub(Container& arr) { + return sprout::sub(arr, sprout::begin(arr), sprout::end(arr)); + } + // // csub // @@ -218,6 +224,12 @@ namespace sprout { return sprout::csub_window(arr, to_first); } + template + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type + csub(Container const& arr) { + return sprout::csub(arr, sprout::begin(arr), sprout::end(arr)); + } + // // sub_copy // @@ -298,6 +310,12 @@ namespace sprout { { return sprout::sub_window_copy(arr, to_first); } + + template + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type + sub_copy(Container const& arr) { + return sprout::sub_copy(arr, sprout::begin(arr), sprout::end(arr)); + } } // namespace sprout #endif // #ifndef SPROUT_SUB_ARRAY_SUB_HPP diff --git a/sprout/utility/string_view/string_view.hpp b/sprout/utility/string_view/string_view.hpp index 7cd8fb97..3f6dfba4 100644 --- a/sprout/utility/string_view/string_view.hpp +++ b/sprout/utility/string_view/string_view.hpp @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include #include @@ -31,7 +31,7 @@ namespace sprout { // // basic_string_view // - template > + template class basic_string_view { public: typedef T value_type; @@ -94,14 +94,14 @@ namespace sprout { : ptr_(str), len_(traits_type::length(str)) {} template - SPROUT_CONSTEXPR basic_string_view(sprout::basic_string const& str) + SPROUT_CONSTEXPR basic_string_view(sprout::basic_string const& str) SPROUT_NOEXCEPT : ptr_(str.data()), len_(str.size()) {} template - SPROUT_NON_CONSTEXPR basic_string_view(std::basic_string const& str) + SPROUT_NON_CONSTEXPR basic_string_view(std::basic_string const& str) SPROUT_NOEXCEPT : ptr_(str.data()), len_(str.size()) {} - SPROUT_CONSTEXPR basic_string_view(const_pointer str, size_type len) + SPROUT_CONSTEXPR basic_string_view(const_pointer str, size_type len) SPROUT_NOEXCEPT : ptr_(str), len_(len) {} // iterators: diff --git a/sprout/utility/string_view/string_view_fwd.hpp b/sprout/utility/string_view/string_view_fwd.hpp new file mode 100644 index 00000000..288bfb39 --- /dev/null +++ b/sprout/utility/string_view/string_view_fwd.hpp @@ -0,0 +1,22 @@ +/*============================================================================= + Copyright (c) 2011-2017 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_UTILITY_STRING_VIEW_STRING_VIEW_FWD_HPP +#define SPROUT_UTILITY_STRING_VIEW_STRING_VIEW_FWD_HPP + +#include +#include + +namespace sprout { + // + // basic_string_view + // + template > + class basic_string_view; +} // namespace sprout + +#endif // #ifndef SPROUT_UTILITY_STRING_VIEW_STRING_VIEW_FWD_HPP diff --git a/sprout/utility/value_holder/value_holder.hpp b/sprout/utility/value_holder/value_holder.hpp index 0e09b6d8..10ece355 100644 --- a/sprout/utility/value_holder/value_holder.hpp +++ b/sprout/utility/value_holder/value_holder.hpp @@ -118,9 +118,11 @@ namespace sprout { return sprout::addressof(p); } static SPROUT_CONSTEXPR reference ref(holder_type r) { - return r ? *r - : (throw sprout::bad_optional_access("value_holder<>: bad optional access"), *r) - ; + return *r; + // !!! +// return r ? *r +// : (throw sprout::bad_optional_access("value_holder<>: bad optional access"), *r) +// ; } static SPROUT_CONSTEXPR pointer ptr(holder_type r) SPROUT_NOEXCEPT { return r; @@ -148,9 +150,11 @@ namespace sprout { return sprout::addressof(p); } static SPROUT_CONSTEXPR reference ref(holder_type r) { - return r ? *r - : (throw sprout::bad_optional_access("value_holder<>: bad optional access"), *r) - ; + return *r; + // !!! +// return r ? *r +// : (throw sprout::bad_optional_access("value_holder<>: bad optional access"), *r) +// ; } static SPROUT_CONSTEXPR pointer ptr(holder_type r) SPROUT_NOEXCEPT { return r; diff --git a/testspr/trace.hpp b/testspr/trace.hpp index a59e0ebe..bce04558 100644 --- a/testspr/trace.hpp +++ b/testspr/trace.hpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -58,6 +59,11 @@ namespace testspr { return what_; } }; + template + inline SPROUT_NON_CONSTEXPR std::basic_ostream& + operator<<(std::basic_ostream& lhs, testspr::trace_info const& rhs) { + return lhs << rhs.file() << ':' << rhs.line() << ": " << rhs.tag() << ": " << rhs.what(); + } // // trace_record @@ -123,9 +129,26 @@ namespace testspr { std::copy(begin(), end(), out); } SPROUT_NON_CONSTEXPR void print() const { - testspr::print_ln("trace-record current: size:", size(), ":"); + testspr::print_ln("trace-record current: size:", size(), ':'); for (const_iterator it = cbegin(), last = cend(); it != last; ++it) { - testspr::print_ln(" ", it->first, " - ", it->second.file(), ":", it->second.line(), ": ", it->second.tag(), ": ", it->second.what()); + testspr::print_ln(" ", it->first, " - ", it->second); + } + } + SPROUT_NON_CONSTEXPR void print_stratified() const { + testspr::print_ln("trace-record current: size:", size(), ':'); + std::string indent; + for (const_iterator it = cbegin(), last = cend(); it != last; ++it) { + if (it->first == "push") { + testspr::print_ln(" ", indent, it->second, " {"); + indent.append(2, ' '); + } else if (it->first == "pop") { + indent.erase(indent.size() - 2); + testspr::print_ln(" ", indent, '}'); + } else if (it->first == "notify") { + testspr::print_ln(" ", indent, it->second); + } else { + testspr::print_ln(" ", indent, it->first, " - ", it->second); + } } } }; @@ -175,16 +198,14 @@ namespace testspr { class print_on_push { public: SPROUT_NON_CONSTEXPR bool operator()(testspr::trace_stack const& stack) const { - testspr::trace_info const& info = stack.top(); - testspr::print_ln("trace-stack push: ", info.file(), ":", info.line(), ": ", info.tag(), ": ", info.what()); + testspr::print_ln("trace-stack push: ", stack.top()); return false; } }; class print_on_pop { public: SPROUT_NON_CONSTEXPR bool operator()(testspr::trace_stack const& stack) const { - testspr::trace_info const& info = stack.top(); - testspr::print_ln("trace-stack pop: ", info.file(), ":", info.line(), ": ", info.tag(), ": ", info.what()); + testspr::print_ln("trace-stack pop: ", stack.top()); return false; } }; @@ -206,7 +227,7 @@ namespace testspr { public: SPROUT_NON_CONSTEXPR bool operator()(testspr::trace_stack const& stack) const { testspr::trace_info const& info = stack.top(); - testspr::print_ln("trace-stack notify: ", info.file(), ":", info.line(), ": ", info.tag(), ": ", info.what()); + testspr::print_ln("trace-stack notify: ", info); if (info.tag() == "assertion-failed") { testspr::trace_stack::instance().print(); testspr::trace_record::instance().print(); @@ -304,9 +325,9 @@ namespace testspr { std::copy(begin(), end(), out); } SPROUT_NON_CONSTEXPR void print() const { - testspr::print_ln("trace-stack current: size:", size(), ":"); + testspr::print_ln("trace-stack current: size:", size(), ':'); for (const_iterator it = cbegin(), last = cend(); it != last; ++it) { - testspr::print_ln(" ", it->file(), ":", it->line(), ": ", it->tag(), ": ", it->what()); + testspr::print_ln(" ", *it); } } @@ -551,6 +572,12 @@ namespace testspr { # define TESTSPR_TRACE_MARK(name) \ ((void)testspr::trace_stack::instance().notify_mark(testspr::to_string(name), __FILE__, __LINE__)) + // + // TESTSPR_PRINT_CURRENT + // +# define TESTSPR_PRINT_CURRENT(name) \ + ((void)testspr::print_ln(testspr::trace_info(__FILE__, __LINE__, "current", name))) + // // TESTSPR_PRINT_TRACE_STACK // TESTSPR_PRINT_TRACE_RECORD @@ -560,6 +587,12 @@ namespace testspr { # define TESTSPR_PRINT_TRACE_RECORD() \ ((void)testspr::trace_record::instance().print()) + // + // TESTSPR_PRINT_STRATIFIED_TRACE_RECORD + // +# define TESTSPR_PRINT_STRATIFIED_TRACE_RECORD() \ + ((void)testspr::trace_record::instance().print_stratified()) + // // TESTSPR_ENABLE_PRINT_ON_ENTRY