Skip to content

Commit

Permalink
Related to #44 .... Range::rank() is now constexpr also (updated TWG:…
Browse files Browse the repository at this point in the history
…:Range spec). Added test to text.C, but only clang++ accepts it. @shiozaki please check with your g++.
  • Loading branch information
evaleev committed Jun 23, 2014
1 parent 5316881 commit 3fa5d06
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
19 changes: 10 additions & 9 deletions btas/range.h
Original file line number Diff line number Diff line change
Expand Up @@ -422,15 +422,6 @@ namespace btas {
return Range1d<typename index_type::value_type>(*(std::begin(lobound_)+d), *(std::begin(upbound_)+d));
}

/// Rank accessor

/// \return The rank (number of dimensions) of this range
/// \throw nothing
size_t rank() const {
using btas::rank;
return rank(lobound_);
}

/// Range lobound coordinate accessor

/// \return A \c size_array that contains the lower bound of this range
Expand All @@ -451,6 +442,16 @@ namespace btas {
return upbound_;
}

/// Rank accessor

/// \return The rank (number of dimensions) of this range
/// \throw nothing
//constexpr auto rank() const -> decltype(btas::rank(this->lobound())) {
constexpr size_t rank() const {
using btas::rank;
return rank(lobound_);
}

/// Range size accessor

/// \return A \c extent_type that contains the extent of each dimension
Expand Down
2 changes: 1 addition & 1 deletion doc/range.dox
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
<td> \c rank() </td>
<td> \c uint </td>
<td> </td>
<td> returns the rank of Range; const </td>
<td> returns the rank of Range; const (and constexpr, if possible) </td>
</tr>

<tr>
Expand Down
9 changes: 9 additions & 0 deletions test/test.C
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ int main()
// default (empty) Range
Range x0;
cout << "x0 = " << x0 << " area=" << x0.area() << endl;
assert(x0.rank() == 0); // std::cout << "rank = 0" << std::endl;

// Range initialized by extents of each dimension
Range x1(3, 2, 3);
Expand Down Expand Up @@ -111,6 +112,14 @@ int main()
Range x6 ({-1, -1, -1}, {2, 3, 4});
cout << "x6 = " << x6 << " area=" << x6.area() << endl;

{
typedef RangeNd<CblasRowMajor, std::array<size_t, 3>> Range3d;
Range3d x;
cout << "Static 3-d Range: x7 = " << x << " area=" << x.area() << endl;
assert(x.rank() == 3);
static_assert(x.rank() == 3, "default Range rank");
}

//////////////////////////////////////////////////////////////////////////////
// Tensor tests
//////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 3fa5d06

Please sign in to comment.