From 117ab524607ddde77ba766dee045ce80ec960279 Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Sat, 17 Aug 2013 00:10:42 +0900 Subject: [PATCH] fix string test --- libs/array/test/array.cpp | 6 ++++++ libs/string/test/string.cpp | 2 +- sprout/array/array.hpp | 39 +++++++++++++++++++++---------------- 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/libs/array/test/array.cpp b/libs/array/test/array.cpp index 7692110b..7728712a 100644 --- a/libs/array/test/array.cpp +++ b/libs/array/test/array.cpp @@ -89,8 +89,14 @@ namespace testspr { // data TESTSPR_BOTH_ASSERT(carr[0] == *arr1.data()); TESTSPR_BOTH_ASSERT(carr[0] == *arr2.data()); + { + auto arr = arr1; + TESTSPR_ASSERT(carr[0] == *arr.data()); + } // c_array + TESTSPR_BOTH_ASSERT(carr[0] == *arr1.c_array()); + TESTSPR_BOTH_ASSERT(carr[0] == *arr2.c_array()); { auto arr = arr1; TESTSPR_ASSERT(carr[0] == *arr.c_array()); diff --git a/libs/string/test/string.cpp b/libs/string/test/string.cpp index 06f22537..7064f129 100644 --- a/libs/string/test/string.cpp +++ b/libs/string/test/string.cpp @@ -299,7 +299,7 @@ namespace testspr { // operator+ { -#ifdef SPROUT_CONFIG_USE_INDEX_ITERATOR_IMPLEMENTATION +#ifdef SPROUT_USE_INDEX_ITERATOR_IMPLEMENTATION // ! Error in GCC4.7 SPROUT_STATIC_CONSTEXPR auto str3 = str1 + sprout::to_string("hogehoge"); TESTSPR_BOTH_ASSERT(str3 == "foobar1234hogehoge"); diff --git a/sprout/array/array.hpp b/sprout/array/array.hpp index c9d4d68f..60b748aa 100644 --- a/sprout/array/array.hpp +++ b/sprout/array/array.hpp @@ -61,12 +61,30 @@ namespace sprout { public: value_type elems[static_size ? static_size : 1]; public: + // construct/copy/destroy: + template + array& operator=(array const& rhs) { + std::copy(rhs.begin(), rhs.end(), begin()); + return *this; + } + template + array& operator=(array&& rhs) { + std::move(rhs.begin(), rhs.end(), begin()); + return *this; + } + // modifiers: void fill(const_reference value) { std::fill_n(begin(), size(), value); } SPROUT_CONSTEXPR array fill(const_reference value) const { return fill_impl(value, sprout::index_n<0, N>::make()); } + void assign(const_reference value) { + fill(value); + } + SPROUT_CONSTEXPR array assign(const_reference value) const { + return fill(value); + } void swap(array& other) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(std::swap(std::declval(), std::declval()))) { @@ -181,26 +199,13 @@ namespace sprout { SPROUT_CONSTEXPR const_pointer data() const SPROUT_NOEXCEPT { return &elems[0]; } - // others: - template - array& operator=(array const& rhs) { - std::copy(rhs.begin(), rhs.end(), begin()); - return *this; - } - template - array& operator=(array&& rhs) { - std::move(rhs.begin(), rhs.end(), begin()); - return *this; - } pointer c_array() SPROUT_NOEXCEPT { - return &elems[0]; + return data(); } - void assign(const_reference value) { - fill(value); - } - SPROUT_CONSTEXPR array assign(const_reference value) const { - return fill(value); + SPROUT_CONSTEXPR const_pointer c_array() const SPROUT_NOEXCEPT { + return data(); } + // others: void rangecheck(size_type i) const { if (i >= size()) { throw std::out_of_range("array<>: index out of range");