From 3fa5d0677ae7f1f8c210c5dc47164764c05446d0 Mon Sep 17 00:00:00 2001 From: Eduard Valeyev Date: Mon, 23 Jun 2014 10:40:40 -0400 Subject: [PATCH] Related to #44 .... Range::rank() is now constexpr also (updated TWG::Range spec). Added test to text.C, but only clang++ accepts it. @shiozaki please check with your g++. --- btas/range.h | 19 ++++++++++--------- doc/range.dox | 2 +- test/test.C | 9 +++++++++ 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/btas/range.h b/btas/range.h index 9fa01385..ffa274e8 100644 --- a/btas/range.h +++ b/btas/range.h @@ -422,15 +422,6 @@ namespace btas { return Range1d(*(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 @@ -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 diff --git a/doc/range.dox b/doc/range.dox index 767c8fcd..187f2383 100644 --- a/doc/range.dox +++ b/doc/range.dox @@ -147,7 +147,7 @@ \c rank() \c uint - returns the rank of Range; const + returns the rank of Range; const (and constexpr, if possible) diff --git a/test/test.C b/test/test.C index 689fc084..e4743dc0 100644 --- a/test/test.C +++ b/test/test.C @@ -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); @@ -111,6 +112,14 @@ int main() Range x6 ({-1, -1, -1}, {2, 3, 4}); cout << "x6 = " << x6 << " area=" << x6.area() << endl; + { + typedef RangeNd> 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 //////////////////////////////////////////////////////////////////////////////