From 9823888049c837c97b1096485143be10d61fea96 Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Tue, 25 Oct 2011 22:04:54 +0900 Subject: [PATCH] =?UTF-8?q?sprout/random/unique=5Fseed.hpp=20=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=20at()=20=E3=83=A1=E3=83=B3=E3=83=90=E9=96=A2?= =?UTF-8?q?=E6=95=B0=E3=82=92=20constexpr=20=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sprout/array.hpp | 14 +++++++++----- sprout/pit.hpp | 14 +++++++++----- sprout/random/unique_seed.hpp | 10 +++++++++- sprout/string.hpp | 14 +++++++++----- sprout/sub_array.hpp | 14 +++++++++----- sprout/uuid/uuid.hpp | 16 ++++++++++------ 6 files changed, 55 insertions(+), 27 deletions(-) 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"); } }