/usr/include/boost/icl/concept
Edit: /usr/include/boost/icl/concept/interval.hpp (53190B)
/*-----------------------------------------------------------------------------+
Copyright (c) 2010-2010: Joachim Faulhaber
+------------------------------------------------------------------------------+
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENCE.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
+-----------------------------------------------------------------------------*/
#ifndef BOOST_ICL_CONCEPT_INTERVAL_HPP_JOFA_100323
#define BOOST_ICL_CONCEPT_INTERVAL_HPP_JOFA_100323
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
namespace boost{namespace icl
{
//==============================================================================
//= Ordering
//==============================================================================
template
inline typename enable_if, bool>::type
domain_less(const typename interval_traits::domain_type& left,
const typename interval_traits::domain_type& right)
{
return typename interval_traits::domain_compare()(left, right);
}
template
inline typename enable_if, bool>::type
domain_less_equal(const typename interval_traits::domain_type& left,
const typename interval_traits::domain_type& right)
{
return !(typename interval_traits::domain_compare()(right, left));
}
template
inline typename enable_if, bool>::type
domain_equal(const typename interval_traits::domain_type& left,
const typename interval_traits::domain_type& right)
{
typedef typename interval_traits::domain_compare domain_compare;
return !(domain_compare()(left, right)) && !(domain_compare()(right, left));
}
template
inline typename enable_if< is_interval
, typename interval_traits::domain_type>::type
domain_next(const typename interval_traits::domain_type value)
{
typedef typename interval_traits::domain_type domain_type;
typedef typename interval_traits::domain_compare domain_compare;
return icl::successor::apply(value);
}
template
inline typename enable_if< is_interval
, typename interval_traits::domain_type>::type
domain_prior(const typename interval_traits::domain_type value)
{
typedef typename interval_traits::domain_type domain_type;
typedef typename interval_traits::domain_compare domain_compare;
return icl::predecessor::apply(value);
}
//==============================================================================
//= Construct singleton
//==============================================================================
template
typename enable_if
<
mpl::and_< is_static_right_open
, is_discrete::domain_type> >
, Type
>::type
singleton(const typename interval_traits::domain_type& value)
{
//ASSERT: This always creates an interval with exactly one element
return interval_traits::construct(value, domain_next(value));
}
template
typename enable_if
<
mpl::and_< is_static_left_open
, is_discrete::domain_type> >
, Type
>::type
singleton(const typename interval_traits::domain_type& value)
{
//ASSERT: This always creates an interval with exactly one element
typedef typename interval_traits::domain_type domain_type;
typedef typename interval_traits::domain_compare domain_compare;
BOOST_ASSERT((numeric_minimum::value>
::is_less_than(value) ));
return interval_traits::construct(domain_prior(value), value);
}
template
typename enable_if, Type>::type
singleton(const typename interval_traits::domain_type& value)
{
//ASSERT: This always creates an interval with exactly one element
typedef typename interval_traits::domain_type domain_type;
typedef typename interval_traits::domain_compare domain_compare;
BOOST_ASSERT((numeric_minimum::value>
::is_less_than(value)));
return interval_traits::construct( domain_prior(value)
, domain_next(value));
}
template
typename enable_if, Type>::type
singleton(const typename interval_traits::domain_type& value)
{
//ASSERT: This always creates an interval with exactly one element
return interval_traits::construct(value, value);
}
template
typename enable_if, Type>::type
singleton(const typename interval_traits::domain_type& value)
{
return dynamic_interval_traits::construct(value, value, interval_bounds::closed());
}
namespace detail
{
//==============================================================================
//= Construct unit_trail == generalized singleton
// The smallest interval on an incrementable (and decrementable) type that can
// be constructed using ++ and -- and such that it contains a given value.
// If 'Type' is discrete, 'unit_trail' and 'singleton' are identical. So we
// can view 'unit_trail' as a generalized singleton for static intervals of
// continuous types.
//==============================================================================
template
typename enable_if
<
mpl::and_< is_static_right_open
, boost::detail::is_incrementable::domain_type> >
, Type
>::type
unit_trail(const typename interval_traits::domain_type& value)
{
return interval_traits::construct(value, domain_next(value));
}
template
typename enable_if
<
mpl::and_< is_static_left_open
, boost::detail::is_incrementable::domain_type> >
, Type
>::type
unit_trail(const typename interval_traits::domain_type& value)
{
typedef typename interval_traits::domain_type domain_type;
typedef typename interval_traits::domain_compare domain_compare;
BOOST_ASSERT((numeric_minimum::value>
::is_less_than(value) ));
return interval_traits::construct(domain_prior(value), value);
}
template
typename enable_if
<
mpl::and_< is_static_open
, is_discrete::domain_type> >
, Type
>::type
unit_trail(const typename interval_traits::domain_type& value)
{
typedef typename interval_traits::domain_type domain_type;
typedef typename interval_traits::domain_compare domain_compare;
BOOST_ASSERT((numeric_minimum::value>
::is_less_than(value)));
return interval_traits::construct( domain_prior(value)
, domain_next(value));
}
template
typename enable_if
<
mpl::and_< is_static_closed
, is_discrete::domain_type> >
, Type
>::type
unit_trail(const typename interval_traits::domain_type& value)
{
return interval_traits::construct(value, value);
}
//NOTE: statically bounded closed or open intervals of continuous domain types
// are NOT supported by ICL. They can not be used with interval containers
// consistently.
template
typename enable_if, Type>::type
unit_trail(const typename interval_traits::domain_type& value)
{
return dynamic_interval_traits::construct(value, value, interval_bounds::closed());
}
} //namespace detail
//==============================================================================
//= Construct multon
//==============================================================================
template
typename enable_if, Type>::type
construct(const typename interval_traits::domain_type& low,
const typename interval_traits::domain_type& up )
{
return interval_traits::construct(low, up);
}
template
typename enable_if, Type>::type
construct(const typename interval_traits::domain_type& low,
const typename interval_traits::domain_type& up,
interval_bounds bounds = interval_bounds::right_open())
{
return dynamic_interval_traits::construct(low, up, bounds);
}
//- construct form bounded values ----------------------------------------------
template
typename enable_if, Type>::type
construct(const typename Type::bounded_domain_type& low,
const typename Type::bounded_domain_type& up)
{
return dynamic_interval_traits::construct_bounded(low, up);
}
template
typename enable_if, Type>::type
span(const typename interval_traits::domain_type& left,
const typename interval_traits::domain_type& right)
{
typedef typename interval_traits::domain_compare domain_compare;
if(domain_compare()(left,right))
return construct(left, right);
else
return construct(right, left);
}
//==============================================================================
template
typename enable_if, Type>::type
hull(const typename interval_traits::domain_type& left,
const typename interval_traits::domain_type& right)
{
typedef typename interval_traits::domain_compare domain_compare;
if(domain_compare()(left,right))
return construct(left, domain_next(right));
else
return construct(right, domain_next(left));
}
template
typename enable_if, Type>::type
hull(const typename interval_traits::domain_type& left,
const typename interval_traits::domain_type& right)
{
typedef typename interval_traits::domain_type domain_type;
typedef typename interval_traits::domain_compare domain_compare;
if(domain_compare()(left,right))
{
BOOST_ASSERT((numeric_minimum::value>
::is_less_than(left) ));
return construct(domain_prior(left), right);
}
else
{
BOOST_ASSERT((numeric_minimum::value>
::is_less_than(right) ));
return construct(domain_prior(right), left);
}
}
template
typename enable_if, Type>::type
hull(const typename interval_traits::domain_type& left,
const typename interval_traits::domain_type& right)
{
typedef typename interval_traits::domain_compare domain_compare;
if(domain_compare()(left,right))
return construct(left, right);
else
return construct(right, left);
}
template
typename enable_if, Type>::type
hull(const typename interval_traits::domain_type& left,
const typename interval_traits::domain_type& right)
{
typedef typename interval_traits::domain_type domain_type;
typedef typename interval_traits::domain_compare domain_compare;
if(domain_compare()(left,right))
{
BOOST_ASSERT((numeric_minimum::value>
::is_less_than(left) ));
return construct( domain_prior(left)
, domain_next(right));
}
else
{
BOOST_ASSERT((numeric_minimum::value>
::is_less_than(right) ));
return construct( domain_prior(right)
, domain_next(left));
}
}
template
typename enable_if, Type>::type
hull(const typename interval_traits::domain_type& left,
const typename interval_traits::domain_type& right)
{
typedef typename interval_traits::domain_compare domain_compare;
if(domain_compare()(left,right))
return construct(left, right, interval_bounds::closed());
else
return construct(right, left, interval_bounds::closed());
}
//==============================================================================
//= Selection
//==============================================================================
template
inline typename enable_if,
typename interval_traits::domain_type>::type
lower(const Type& object)
{
return interval_traits::lower(object);
}
template
inline typename enable_if,
typename interval_traits::domain_type>::type
upper(const Type& object)
{
return interval_traits::upper(object);
}
//- first ----------------------------------------------------------------------
template
inline typename
enable_if< mpl::or_, is_static_closed >
, typename interval_traits::domain_type>::type
first(const Type& object)
{
return lower(object);
}
template
inline typename
enable_if< mpl::and_< mpl::or_, is_static_open >
, is_discrete::domain_type> >
, typename interval_traits::domain_type>::type
first(const Type& object)
{
return domain_next(lower(object));
}
template
inline typename enable_if,
typename interval_traits::domain_type>::type
first(const Type& object)
{
return is_left_closed(object.bounds()) ?
lower(object) :
domain_next(lower(object));
}
//- last -----------------------------------------------------------------------
template
inline typename
enable_if< mpl::or_, is_static_closed >
, typename interval_traits::domain_type>::type
last(const Type& object)
{
return upper(object);
}
template
inline typename
enable_if< mpl::and_< mpl::or_, is_static_open >
, is_discrete::domain_type> >
, typename interval_traits::domain_type>::type
last(const Type& object)
{
typedef typename interval_traits::domain_type domain_type;
typedef typename interval_traits::domain_compare domain_compare;
BOOST_ASSERT((numeric_minimum::value>
::is_less_than(upper(object)) ));
return domain_prior(upper(object));
}
template
inline typename enable_if,
typename interval_traits::domain_type>::type
last(const Type& object)
{
typedef typename interval_traits::domain_type domain_type;
typedef typename interval_traits::domain_compare domain_compare;
BOOST_ASSERT((numeric_minimum::value>
::is_less_than_or(upper(object), is_right_closed(object.bounds())) ));
return is_right_closed(object.bounds()) ?
upper(object) :
domain_prior(upper(object));
}
//- last_next ------------------------------------------------------------------
template
inline typename
enable_if< mpl::and_< mpl::or_, is_static_closed >
, is_discrete::domain_type> >
, typename interval_traits::domain_type>::type
last_next(const Type& object)
{
return domain_next(upper(object));
}
template
inline typename
enable_if< mpl::and_< mpl::or_, is_static_open >
, is_discrete::domain_type> >
, typename interval_traits::domain_type>::type
last_next(const Type& object)
{
//CL typedef typename interval_traits::domain_type domain_type;
return upper(object); // NOTE: last_next is implemented to avoid calling pred(object)
} // For unsigned integral types this may cause underflow.
template
inline typename enable_if,
typename interval_traits::domain_type>::type
last_next(const Type& object)
{
return is_right_closed(object.bounds()) ?
domain_next(upper(object)):
upper(object) ;
}
//------------------------------------------------------------------------------
template
typename enable_if,
typename Type::bounded_domain_type>::type
bounded_lower(const Type& object)
{
return typename
Type::bounded_domain_type(lower(object), object.bounds().left());
}
template
typename enable_if,
typename Type::bounded_domain_type>::type
reverse_bounded_lower(const Type& object)
{
return typename
Type::bounded_domain_type(lower(object),
object.bounds().reverse_left());
}
template
typename enable_if,
typename Type::bounded_domain_type>::type
bounded_upper(const Type& object)
{
return typename
Type::bounded_domain_type(upper(object),
object.bounds().right());
}
template
typename enable_if,
typename Type::bounded_domain_type>::type
reverse_bounded_upper(const Type& object)
{
return typename
Type::bounded_domain_type(upper(object),
object.bounds().reverse_right());
}
//- bounds ---------------------------------------------------------------------
template