Skip to content

Commit

Permalink
*
Browse files Browse the repository at this point in the history
  • Loading branch information
muellan committed Jun 2, 2014
1 parent 0d8efd6 commit fa6d107
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 55 deletions.
74 changes: 22 additions & 52 deletions bounded.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include <cstdint>
#include <cfloat>
#include <iostream>
#include <sstream>

#include "interval.h"
#include "equality.h"
Expand Down Expand Up @@ -65,27 +64,6 @@ struct clip_and_report
}
};

//-------------------------------------------------------------------
struct throw_if_out_of_bounds
{
template<class T>
T
operator () (T x, const T& min, const T& max)
{
if(x < min) {
std::ostringstream os;
os << x << " below [" << min << ',' << max << "]\n";
throw std::out_of_range(os.str());
}
else if(x > max) {
std::ostringstream os;
os << x << " above [" << min << ',' << max << "]\n";
throw std::out_of_range(os.str());
}
return x;
}
};




Expand Down Expand Up @@ -178,13 +156,14 @@ class bounded :
/// @brief
template<class T, class = typename std::enable_if<
is_number<T>::value>::type>
explicit constexpr
constexpr
bounded(T&& v,
interval_type b = interval_type(),
bounding_policy bp = bounding_policy())
:
interval_type(std::move(b)), bounding_policy(std::move(bp)),
v_(get_bounded(value_type(std::forward<T>(v))))
v_(get_bounded(std::forward<T>(v)))

{
AM_CHECK_NARROWING(value_type,T)
}
Expand All @@ -204,7 +183,7 @@ class bounded :
explicit constexpr
bounded(T&& v, bounding_policy bp) :
interval_type(), bounding_policy(std::move(bp)),
v_(get_bounded(value_type(std::forward<T>(v))))
v_(get_bounded(std::forward<T>(v)))
{
AM_CHECK_NARROWING(value_type,T)
}
Expand All @@ -217,7 +196,7 @@ class bounded :
bounding_policy bp = bounding_policy())
:
interval_type(std::move(b)), bounding_policy(std::move(bp)),
v_(get_bounded(value_type(v)))
v_(value_type(v))
{
AM_CHECK_NARROWING(value_type,T)
}
Expand Down Expand Up @@ -461,8 +440,8 @@ class bounded :


private:
value_type
get_bounded(value_type v) {
constexpr value_type
get_bounded(value_type v) const noexcept {
return bounding_policy::operator()(std::move(v), min(), max());
}

Expand Down Expand Up @@ -1110,6 +1089,21 @@ abs(const bounded<T,B,P>& x)
return bounded<T,B,P>(abs(x.value()));
}

//---------------------------------------------------------
template<class T, class B, class P>
inline constexpr auto
min(const bounded<T,B,P>& x) -> decltype(x.min())
{
return x.min();
}
//---------------------------------------------------------
template<class T, class B, class P>
inline constexpr auto
max(const bounded<T,B,P>& x) -> decltype(x.max())
{
return x.max();
}




Expand Down Expand Up @@ -1289,30 +1283,6 @@ struct common_bounding_policy<silent_clip,clip_and_report> {
using type = clip_and_report;
};

//---------------------------------------------------------
template<>
struct common_bounding_policy<silent_clip,throw_if_out_of_bounds> {
using type = throw_if_out_of_bounds;
};

//---------------------------------------------------------
template<>
struct common_bounding_policy<throw_if_out_of_bounds,silent_clip> {
using type = throw_if_out_of_bounds;
};

//---------------------------------------------------------
template<>
struct common_bounding_policy<clip_and_report,throw_if_out_of_bounds> {
using type = throw_if_out_of_bounds;
};

//---------------------------------------------------------
template<>
struct common_bounding_policy<throw_if_out_of_bounds,clip_and_report> {
using type = throw_if_out_of_bounds;
};



//-------------------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions rounded.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class rounded :
/// @brief
template<class T, class = typename std::enable_if<
is_number<T>::value>::type>
explicit constexpr
constexpr
rounded(T&& v, rounding_method rp = rounding_method()) :
rounding_method(std::move(rp)),
v_(corrected(value_type(std::forward<T>(v))))
Expand Down Expand Up @@ -403,8 +403,8 @@ class rounded :


private:
value_type
corrected(value_type v) {
constexpr value_type
corrected(value_type v) const noexcept {
return rounding_method::operator()(std::move(v));
}

Expand Down

0 comments on commit fa6d107

Please sign in to comment.