return Range<T*>(array, array + n);
}
+template <class T, size_t n>
+constexpr Range<const T*> range(const std::array<T, n>& array) {
+ using r = Range<const T*>;
+ return array.empty() ? r{} : r(&array.at(0), &array.at(0) + n);
+}
+
typedef Range<const char*> StringPiece;
typedef Range<char*> MutableStringPiece;
typedef Range<const unsigned char*> ByteRange;
EXPECT_EQ(4, numArrayRangeSize);
}
+TEST(RangeFunc, ConstexprStdArray) {
+ static constexpr const std::array<int, 4> numArray = {3, 17, 1, 9};
+ constexpr const auto numArrayRange = range(numArray);
+ EXPECT_EQ(17, numArrayRange[1]);
+ constexpr const auto numArrayRangeSize = numArrayRange.size();
+ EXPECT_EQ(4, numArrayRangeSize);
+}
+
+TEST(RangeFunc, ConstexprStdArrayZero) {
+ static constexpr const std::array<int, 0> numArray = {};
+ constexpr const auto numArrayRange = range(numArray);
+ constexpr const auto numArrayRangeSize = numArrayRange.size();
+ EXPECT_EQ(0, numArrayRangeSize);
+}
+
TEST(RangeFunc, ConstexprIteratorPair) {
static constexpr const int numArray[4] = {3, 17, 1, 9};
constexpr const auto numPtr = static_cast<const int*>(numArray);