types: remove elems function, prefer std::size
Now that std::size is part of our supported compilers we can remove the old elems function.
This commit is contained in:
parent
70f0fdd830
commit
a93dd90da9
@ -94,7 +94,7 @@ debug::operator<< (std::ostream &os, const debug::backtrace &b)
|
||||
} sym;
|
||||
|
||||
sym.info.SizeOfStruct = sizeof (sym.info);
|
||||
sym.info.MaxNameLength = elems (sym.name);
|
||||
sym.info.MaxNameLength = std::size (sym.name);
|
||||
|
||||
for (auto frame: b.frames ()) {
|
||||
// Find the symbol name
|
||||
|
@ -189,7 +189,7 @@ win32_error::code_string (DWORD code)
|
||||
code,
|
||||
MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
message,
|
||||
elems (message),
|
||||
std::size (message),
|
||||
NULL
|
||||
);
|
||||
|
||||
|
@ -142,7 +142,7 @@ MD2::transform (void)
|
||||
// only change keeping us from conforming to the test-cases. Pulled from a
|
||||
// review of the reference implementation.
|
||||
uint8_t L = C[15];
|
||||
for (size_t i = 0; i < elems (C); ++i)
|
||||
for (size_t i = 0; i < std::size (C); ++i)
|
||||
L = C[i] ^= S[M[i] ^ L];
|
||||
|
||||
uint8_t t = 0;
|
||||
|
@ -19,12 +19,12 @@ test_null (util::TAP::logger &tap)
|
||||
|
||||
static const char *argv1[] = { "./foo", "-n", "foo" };
|
||||
tap.expect_nothrow ([&] () {
|
||||
p.scan (elems (argv1), argv1);
|
||||
p.scan (std::size (argv1), argv1);
|
||||
}, "nothrow null short form");
|
||||
|
||||
static const char *argv2[] = { "./foo", "--null", "foo" };
|
||||
tap.expect_nothrow ([&] () {
|
||||
p.scan (elems (argv2), argv2);
|
||||
p.scan (std::size (argv2), argv2);
|
||||
}, "nothrow null long form");
|
||||
}
|
||||
|
||||
@ -44,7 +44,7 @@ test_present (util::TAP::logger &tap)
|
||||
{
|
||||
static const char *argv1[] = { "./foo", "-p" };
|
||||
is_present = false;
|
||||
p.scan (elems (argv1), argv1);
|
||||
p.scan (std::size (argv1), argv1);
|
||||
tap.expect (is_present, "presence short form");
|
||||
}
|
||||
|
||||
@ -52,7 +52,7 @@ test_present (util::TAP::logger &tap)
|
||||
{
|
||||
static const char *argv2[] = { "./foo", "--present" };
|
||||
is_present = false;
|
||||
p.scan (elems (argv2), argv2);
|
||||
p.scan (std::size (argv2), argv2);
|
||||
tap.expect (is_present, "presence long form");
|
||||
}
|
||||
|
||||
@ -60,7 +60,7 @@ test_present (util::TAP::logger &tap)
|
||||
{
|
||||
static const char *argv3[] = { "./foo" };
|
||||
is_present = true;
|
||||
p.scan (elems (argv3), argv3);
|
||||
p.scan (std::size (argv3), argv3);
|
||||
tap.expect (!is_present, "presence null");
|
||||
}
|
||||
}
|
||||
@ -131,7 +131,7 @@ test_numeric (util::TAP::logger &tap)
|
||||
const char *argv_short[] = { "./foo", "-t", NULL };
|
||||
const char * argv_long[] = { "./foo", NULL };
|
||||
|
||||
for(size_t i = 0; i < elems (values); ++i) {
|
||||
for(size_t i = 0; i < std::size (values); ++i) {
|
||||
std::ostringstream out_short, out_long;
|
||||
std::string str_short, str_long;
|
||||
|
||||
@ -142,7 +142,7 @@ test_numeric (util::TAP::logger &tap)
|
||||
|
||||
// check short form reading
|
||||
value = 2;
|
||||
p.scan (elems (argv_short), argv_short);
|
||||
p.scan (std::size (argv_short), argv_short);
|
||||
tap.expect_eq (value, values[i], "equality, short form");
|
||||
|
||||
// construct long form arguments
|
||||
@ -152,7 +152,7 @@ test_numeric (util::TAP::logger &tap)
|
||||
|
||||
// check long form reading
|
||||
value = 2;
|
||||
p.scan (elems (argv_long), argv_long);
|
||||
p.scan (std::size (argv_long), argv_long);
|
||||
tap.expect_eq (value, values[i], "equality, long form");
|
||||
}
|
||||
}
|
||||
@ -186,7 +186,7 @@ test_bytes (util::TAP::logger &tap)
|
||||
|
||||
for (auto &i: commands) {
|
||||
argv[2] = i.str;
|
||||
p.scan (elems (argv), argv);
|
||||
p.scan (std::size (argv), argv);
|
||||
|
||||
tap.expect_eq (i.val, size, "bytes, %s", i.str);
|
||||
};
|
||||
@ -212,7 +212,7 @@ test_required (util::TAP::logger &tap)
|
||||
};
|
||||
|
||||
tap.expect_nothrow ([&] () {
|
||||
p.scan (elems (argv), argv);
|
||||
p.scan (std::size (argv), argv);
|
||||
}, "required option, success");
|
||||
|
||||
tap.expect_throw<util::cmdopt::invalid_required> ([&] () {
|
||||
@ -239,7 +239,7 @@ test_positional (util::TAP::logger &tap)
|
||||
};
|
||||
|
||||
tap.expect_nothrow ([&] {
|
||||
p.scan (elems (argv), argv);
|
||||
p.scan (std::size (argv), argv);
|
||||
}, "positional, nothrow");
|
||||
|
||||
tap.expect_eq (value, expected, "positiona, value success");
|
||||
|
@ -16,7 +16,7 @@ main ()
|
||||
|
||||
struct {
|
||||
std::vector<uint8_t> key;
|
||||
const uint64_t data[elems (OFFSETS)][16];
|
||||
const uint64_t data[std::size (OFFSETS)][16];
|
||||
} TESTS[] = {
|
||||
{
|
||||
{ 1, 2, 3, 4, 5 },
|
||||
@ -365,7 +365,7 @@ main ()
|
||||
},
|
||||
};
|
||||
|
||||
for (size_t i = 0; i < elems (TESTS); ++i) {
|
||||
for (size_t i = 0; i < std::size (TESTS); ++i) {
|
||||
const auto &t = TESTS[i];
|
||||
|
||||
util::crypto::ARC4 gen (t.key.data (), t.key.size ());
|
||||
@ -373,7 +373,7 @@ main ()
|
||||
size_t consumed = 0;
|
||||
bool success = true;
|
||||
|
||||
for (size_t j = 0; j < elems (OFFSETS); ++j) {
|
||||
for (size_t j = 0; j < std::size (OFFSETS); ++j) {
|
||||
CHECK_GE (OFFSETS[j], consumed);
|
||||
|
||||
size_t diff = OFFSETS[j] - consumed;
|
||||
|
@ -40,7 +40,7 @@ main ()
|
||||
|
||||
util::TAP::logger tap;
|
||||
|
||||
for (size_t i = 0; i < elems (TESTS); ++i) {
|
||||
for (size_t i = 0; i < std::size (TESTS); ++i) {
|
||||
const auto &t = TESTS[i];
|
||||
util::crypto::TEA gen (t.key);
|
||||
|
||||
|
@ -39,7 +39,7 @@ main ()
|
||||
|
||||
util::TAP::logger tap;
|
||||
|
||||
for (size_t i = 0; i < elems (TESTS); ++i) {
|
||||
for (size_t i = 0; i < std::size (TESTS); ++i) {
|
||||
const auto &t = TESTS[i];
|
||||
util::crypto::XTEA gen (t.key);
|
||||
|
||||
|
@ -92,7 +92,7 @@ main ()
|
||||
|
||||
util::TAP::logger tap;
|
||||
|
||||
for (size_t i = 0; i < elems (TESTS); ++i) {
|
||||
for (size_t i = 0; i < std::size (TESTS); ++i) {
|
||||
const auto &t = TESTS[i];
|
||||
|
||||
CHECK_EQ (t.dec.size (), t.enc.size ());
|
||||
|
@ -26,7 +26,7 @@ main (void)
|
||||
for (auto p: util::extent_range2u ({3, 3}))
|
||||
success += EXPECTED[offset++] == p ? 1 : 0;
|
||||
|
||||
tap.expect_eq (success, elems (EXPECTED), "extent_range2u iteration");
|
||||
tap.expect_eq (success, std::size (EXPECTED), "extent_range2u iteration");
|
||||
}
|
||||
|
||||
return tap.status ();
|
||||
|
@ -34,7 +34,7 @@ test_double (util::TAP::logger &tap)
|
||||
|
||||
bool success = true;
|
||||
|
||||
for (unsigned int i = 0; i < elems (tests); ++i) {
|
||||
for (unsigned int i = 0; i < std::size (tests); ++i) {
|
||||
util::ieee_double val;
|
||||
val.set_bits (tests[i].bits);
|
||||
|
||||
@ -70,7 +70,7 @@ test_single (util::TAP::logger &tap)
|
||||
|
||||
bool success = true;
|
||||
|
||||
for (unsigned int i = 0; i < elems (tests); ++i) {
|
||||
for (unsigned int i = 0; i < std::size (tests); ++i) {
|
||||
util::ieee_single val;
|
||||
val.set_bits (tests[i].bits);
|
||||
|
||||
|
@ -273,7 +273,7 @@ main (int, char**)
|
||||
{
|
||||
util::TAP::logger tap;
|
||||
|
||||
for (size_t i = 0; i < elems (TESTS); ++i)
|
||||
for (size_t i = 0; i < std::size (TESTS); ++i)
|
||||
tap.expect (TESTS[i].fun (TESTS[i].key, TESTS[i].dat, TESTS[i].res), "standard test vector %zu", i);
|
||||
|
||||
return tap.status ();
|
||||
|
@ -82,7 +82,7 @@ main (void)
|
||||
{ 1.f, { 0.f, 0.f, 1.f } },
|
||||
};
|
||||
|
||||
for (size_t i = 0; i < elems (ROTATIONS); ++i) {
|
||||
for (size_t i = 0; i < std::size (ROTATIONS); ++i) {
|
||||
const auto &r = ROTATIONS[i];
|
||||
|
||||
auto q = quaternionf::angle_axis (r.mag, r.axis).as_matrix ();
|
||||
|
@ -17,7 +17,7 @@ main (int, char**)
|
||||
{ "" }
|
||||
};
|
||||
|
||||
std::string str (std::cbegin (csv), std::cbegin (csv) + elems (csv));
|
||||
std::string str (std::cbegin (csv), std::cbegin (csv) + std::size (csv));
|
||||
auto tok = util::make_tokeniser (str, ',');
|
||||
auto t_cursor = tok.cbegin ();
|
||||
auto v_cursor = std::cbegin (values);
|
||||
|
13
types.hpp
13
types.hpp
@ -22,19 +22,6 @@
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// Returns the number of elements of a statically allocated array
|
||||
template <typename T, size_t N>
|
||||
constexpr size_t
|
||||
elems (const T (&)[N])
|
||||
{ return N; }
|
||||
|
||||
|
||||
template <typename T>
|
||||
constexpr typename T::size_type
|
||||
elems (const T &t)
|
||||
{ return t.size (); }
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// analogue of std::data for use until we get proper c++17 support
|
||||
|
Loading…
Reference in New Issue
Block a user