diff --git a/sprout/array.hpp b/sprout/array.hpp index 484c18b8..87d498b2 100644 --- a/sprout/array.hpp +++ b/sprout/array.hpp @@ -130,12 +130,16 @@ namespace sprout { return elems[i]; } reference at(size_type i) { - rangecheck(i); - return elems[i]; + return i < size() + ? elems[i] + : (throw std::out_of_range("array<>: index out of range"), elems[i]) + ; } - const_reference at(size_type i) const { - rangecheck(i); - return elems[i]; + SPROUT_CONSTEXPR const_reference at(size_type i) const { + return i < size() + ? elems[i] + : (throw std::out_of_range("array<>: index out of range"), elems[i]) + ; } reference front() { return elems[0]; diff --git a/sprout/pit.hpp b/sprout/pit.hpp index 447507c5..4a5a4b91 100644 --- a/sprout/pit.hpp +++ b/sprout/pit.hpp @@ -98,12 +98,16 @@ namespace sprout { return elem; } reference at(size_type i) { - rangecheck(i); - return elem; + return i < size() + ? elem + : (throw std::out_of_range("pit<>: index out of range"), elem) + ; } - const_reference at(size_type i) const { - rangecheck(i); - return elem; + SPROUT_CONSTEXPR const_reference at(size_type i) const { + return i < size() + ? elem + : (throw std::out_of_range("pit<>: index out of range"), elem) + ; } reference front() { return elem; diff --git a/sprout/random/unique_seed.hpp b/sprout/random/unique_seed.hpp index 9c0f2244..b201ab44 100644 --- a/sprout/random/unique_seed.hpp +++ b/sprout/random/unique_seed.hpp @@ -1,6 +1,10 @@ #ifndef SPROUT_RANDOM_UNIQUE_SEED_HPP #define SPROUT_RANDOM_UNIQUE_SEED_HPP +#ifndef SPROUT_CONFIG_DISABLE_CONSTEXPR +# include +# include +#endif #include #include #include @@ -8,7 +12,11 @@ // // SPROUT_UNIQUE_SEED // -#define SPROUT_UNIQUE_SEED (::sprout::hash_value(SPROUT_PP_UNIQUE_STRING)) +#ifndef SPROUT_CONFIG_DISABLE_CONSTEXPR +# define SPROUT_UNIQUE_SEED (::std::integral_constant< ::std::size_t, ::sprout::hash_value(SPROUT_PP_UNIQUE_STRING)>::value) +#else +# define SPROUT_UNIQUE_SEED (::sprout::hash_value(SPROUT_PP_UNIQUE_STRING)) +#endif #endif // #ifndef SPROUT_RANDOM_UNIQUE_SEED_HPP diff --git a/sprout/string.hpp b/sprout/string.hpp index 1ba8af92..a3a1c2c5 100644 --- a/sprout/string.hpp +++ b/sprout/string.hpp @@ -375,12 +375,16 @@ namespace sprout { return elems[i]; } reference at(size_type i) { - rangecheck(i); - return elems[i]; + return i < size() + ? elems[i] + : (throw std::out_of_range("basic_string<>: index out of range"), elems[i]) + ; } - const_reference at(size_type i) const { - rangecheck(i); - return elems[i]; + SPROUT_CONSTEXPR const_reference at(size_type i) const { + return i < size() + ? elems[i] + : (throw std::out_of_range("basic_string<>: index out of range"), elems[i]) + ; } reference front() { return elems[0]; diff --git a/sprout/sub_array.hpp b/sprout/sub_array.hpp index d8c2a381..97153f71 100644 --- a/sprout/sub_array.hpp +++ b/sprout/sub_array.hpp @@ -310,12 +310,16 @@ namespace sprout { return *sprout::next(sprout::begin(get_array()), first_ + i); } reference at(size_type i) { - rangecheck(i); - return *sprout::next(sprout::begin(get_array()), first_ + i); + return i < size() + ? *sprout::next(sprout::begin(get_array()), first_ + i) + : (throw std::out_of_range("sub_array<>: index out of range"), *sprout::next(sprout::begin(get_array()), first_ + i)) + ; } - const_reference at(size_type i) const { - rangecheck(i); - return *sprout::next(sprout::begin(get_array()), first_ + i); + SPROUT_CONSTEXPR const_reference at(size_type i) const { + return i < size() + ? *sprout::next(sprout::begin(get_array()), first_ + i) + : (throw std::out_of_range("sub_array<>: index out of range"), *sprout::next(sprout::begin(get_array()), first_ + i)) + ; } reference front() { return *sprout::next(sprout::begin(get_array()), first_); diff --git a/sprout/uuid/uuid.hpp b/sprout/uuid/uuid.hpp index b0492af2..3ce6a8c6 100644 --- a/sprout/uuid/uuid.hpp +++ b/sprout/uuid/uuid.hpp @@ -157,12 +157,16 @@ namespace sprout { return elems[i]; } reference at(size_type i) { - rangecheck(i); - return elems[i]; + return i < size() + ? elems[i] + : (throw std::out_of_range("uuid: index out of range"), elems[i]) + ; } - const_reference at(size_type i) const { - rangecheck(i); - return elems[i]; + SPROUT_CONSTEXPR const_reference at(size_type i) const { + return i < size() + ? elems[i] + : (throw std::out_of_range("uuid: index out of range"), elems[i]) + ; } reference front() { return elems[0]; @@ -193,7 +197,7 @@ namespace sprout { } void rangecheck(size_type i) const { if (i >= size()) { - throw std::out_of_range("uuid<>: index out of range"); + throw std::out_of_range("uuid: index out of range"); } }