Boost logo

Boost Users :

Subject: [Boost-users] Why must a Single Pass Range be default constructible?
From: athor (thorena_at_[hidden])
Date: 2009-04-21 11:31:54


A Range does not require copy semantics according to the boost docs.
http://www.boost.org/doc/libs/1_38_0/libs/range/doc/range.html

The SinglePassRangeConcept (and all range concepts using it) requires a
range to be default constructible. (There is a line "T a;" in the concept

The default constructible requirement means an abstract base class can never
implement any Range Concept. If a range does not require any copy semantics,
I don't see why it must be default constructible? Are there any good reasons
I don't know about?

A change from "T a;" to "const T& a" in concepts.hpp would do the trick...

Example:
struct AbstractArraySlice
{
int* begin() const = 0;
int* end() const = 0;
};

// FAILS:
BOOST_CONCEPT_ASSERT((SinglePassRangeConcept<AbstractArraySlice>))

Footnote:
I often use abstract base classes to verify my algorithms do not use more
functionality than necessary and it annoys me that I can't use the range
concept check:

struct TestSum
{
  const AbstractArraySlice& r;
  void Test()
  {
  CalculateSum(r);
  }
};

template<class T>
T CalculateSum(const T& range)
<... function requires SinglePassRangeConcept ...>

-- 
View this message in context: http://www.nabble.com/Why-must-a-Single-Pass-Range-be-default-constructible--tp23158703p23158703.html
Sent from the Boost - Users mailing list archive at Nabble.com.

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net