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:
Danny Robson 2016-11-17 18:06:39 +11:00
parent 70f0fdd830
commit a93dd90da9
14 changed files with 26 additions and 39 deletions

View File

@ -94,7 +94,7 @@ debug::operator<< (std::ostream &os, const debug::backtrace &b)
} sym; } sym;
sym.info.SizeOfStruct = sizeof (sym.info); sym.info.SizeOfStruct = sizeof (sym.info);
sym.info.MaxNameLength = elems (sym.name); sym.info.MaxNameLength = std::size (sym.name);
for (auto frame: b.frames ()) { for (auto frame: b.frames ()) {
// Find the symbol name // Find the symbol name

View File

@ -189,7 +189,7 @@ win32_error::code_string (DWORD code)
code, code,
MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
message, message,
elems (message), std::size (message),
NULL NULL
); );

View File

@ -142,7 +142,7 @@ MD2::transform (void)
// only change keeping us from conforming to the test-cases. Pulled from a // only change keeping us from conforming to the test-cases. Pulled from a
// review of the reference implementation. // review of the reference implementation.
uint8_t L = C[15]; 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]; L = C[i] ^= S[M[i] ^ L];
uint8_t t = 0; uint8_t t = 0;

View File

@ -19,12 +19,12 @@ test_null (util::TAP::logger &tap)
static const char *argv1[] = { "./foo", "-n", "foo" }; static const char *argv1[] = { "./foo", "-n", "foo" };
tap.expect_nothrow ([&] () { tap.expect_nothrow ([&] () {
p.scan (elems (argv1), argv1); p.scan (std::size (argv1), argv1);
}, "nothrow null short form"); }, "nothrow null short form");
static const char *argv2[] = { "./foo", "--null", "foo" }; static const char *argv2[] = { "./foo", "--null", "foo" };
tap.expect_nothrow ([&] () { tap.expect_nothrow ([&] () {
p.scan (elems (argv2), argv2); p.scan (std::size (argv2), argv2);
}, "nothrow null long form"); }, "nothrow null long form");
} }
@ -44,7 +44,7 @@ test_present (util::TAP::logger &tap)
{ {
static const char *argv1[] = { "./foo", "-p" }; static const char *argv1[] = { "./foo", "-p" };
is_present = false; is_present = false;
p.scan (elems (argv1), argv1); p.scan (std::size (argv1), argv1);
tap.expect (is_present, "presence short form"); tap.expect (is_present, "presence short form");
} }
@ -52,7 +52,7 @@ test_present (util::TAP::logger &tap)
{ {
static const char *argv2[] = { "./foo", "--present" }; static const char *argv2[] = { "./foo", "--present" };
is_present = false; is_present = false;
p.scan (elems (argv2), argv2); p.scan (std::size (argv2), argv2);
tap.expect (is_present, "presence long form"); tap.expect (is_present, "presence long form");
} }
@ -60,7 +60,7 @@ test_present (util::TAP::logger &tap)
{ {
static const char *argv3[] = { "./foo" }; static const char *argv3[] = { "./foo" };
is_present = true; is_present = true;
p.scan (elems (argv3), argv3); p.scan (std::size (argv3), argv3);
tap.expect (!is_present, "presence null"); 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_short[] = { "./foo", "-t", NULL };
const char * argv_long[] = { "./foo", 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::ostringstream out_short, out_long;
std::string str_short, str_long; std::string str_short, str_long;
@ -142,7 +142,7 @@ test_numeric (util::TAP::logger &tap)
// check short form reading // check short form reading
value = 2; 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"); tap.expect_eq (value, values[i], "equality, short form");
// construct long form arguments // construct long form arguments
@ -152,7 +152,7 @@ test_numeric (util::TAP::logger &tap)
// check long form reading // check long form reading
value = 2; 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"); tap.expect_eq (value, values[i], "equality, long form");
} }
} }
@ -186,7 +186,7 @@ test_bytes (util::TAP::logger &tap)
for (auto &i: commands) { for (auto &i: commands) {
argv[2] = i.str; 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); tap.expect_eq (i.val, size, "bytes, %s", i.str);
}; };
@ -212,7 +212,7 @@ test_required (util::TAP::logger &tap)
}; };
tap.expect_nothrow ([&] () { tap.expect_nothrow ([&] () {
p.scan (elems (argv), argv); p.scan (std::size (argv), argv);
}, "required option, success"); }, "required option, success");
tap.expect_throw<util::cmdopt::invalid_required> ([&] () { tap.expect_throw<util::cmdopt::invalid_required> ([&] () {
@ -239,7 +239,7 @@ test_positional (util::TAP::logger &tap)
}; };
tap.expect_nothrow ([&] { tap.expect_nothrow ([&] {
p.scan (elems (argv), argv); p.scan (std::size (argv), argv);
}, "positional, nothrow"); }, "positional, nothrow");
tap.expect_eq (value, expected, "positiona, value success"); tap.expect_eq (value, expected, "positiona, value success");

View File

@ -16,7 +16,7 @@ main ()
struct { struct {
std::vector<uint8_t> key; std::vector<uint8_t> key;
const uint64_t data[elems (OFFSETS)][16]; const uint64_t data[std::size (OFFSETS)][16];
} TESTS[] = { } TESTS[] = {
{ {
{ 1, 2, 3, 4, 5 }, { 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]; const auto &t = TESTS[i];
util::crypto::ARC4 gen (t.key.data (), t.key.size ()); util::crypto::ARC4 gen (t.key.data (), t.key.size ());
@ -373,7 +373,7 @@ main ()
size_t consumed = 0; size_t consumed = 0;
bool success = true; 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); CHECK_GE (OFFSETS[j], consumed);
size_t diff = OFFSETS[j] - consumed; size_t diff = OFFSETS[j] - consumed;

View File

@ -40,7 +40,7 @@ main ()
util::TAP::logger tap; 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]; const auto &t = TESTS[i];
util::crypto::TEA gen (t.key); util::crypto::TEA gen (t.key);

View File

@ -39,7 +39,7 @@ main ()
util::TAP::logger tap; 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]; const auto &t = TESTS[i];
util::crypto::XTEA gen (t.key); util::crypto::XTEA gen (t.key);

View File

@ -92,7 +92,7 @@ main ()
util::TAP::logger tap; 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]; const auto &t = TESTS[i];
CHECK_EQ (t.dec.size (), t.enc.size ()); CHECK_EQ (t.dec.size (), t.enc.size ());

View File

@ -26,7 +26,7 @@ main (void)
for (auto p: util::extent_range2u ({3, 3})) for (auto p: util::extent_range2u ({3, 3}))
success += EXPECTED[offset++] == p ? 1 : 0; 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 (); return tap.status ();

View File

@ -34,7 +34,7 @@ test_double (util::TAP::logger &tap)
bool success = true; 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; util::ieee_double val;
val.set_bits (tests[i].bits); val.set_bits (tests[i].bits);
@ -70,7 +70,7 @@ test_single (util::TAP::logger &tap)
bool success = true; 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; util::ieee_single val;
val.set_bits (tests[i].bits); val.set_bits (tests[i].bits);

View File

@ -273,7 +273,7 @@ main (int, char**)
{ {
util::TAP::logger tap; 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); tap.expect (TESTS[i].fun (TESTS[i].key, TESTS[i].dat, TESTS[i].res), "standard test vector %zu", i);
return tap.status (); return tap.status ();

View File

@ -82,7 +82,7 @@ main (void)
{ 1.f, { 0.f, 0.f, 1.f } }, { 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]; const auto &r = ROTATIONS[i];
auto q = quaternionf::angle_axis (r.mag, r.axis).as_matrix (); auto q = quaternionf::angle_axis (r.mag, r.axis).as_matrix ();

View File

@ -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 tok = util::make_tokeniser (str, ',');
auto t_cursor = tok.cbegin (); auto t_cursor = tok.cbegin ();
auto v_cursor = std::cbegin (values); auto v_cursor = std::cbegin (values);

View File

@ -22,19 +22,6 @@
#include <memory> #include <memory>
#include <stdexcept> #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 // analogue of std::data for use until we get proper c++17 support