diff --git a/backtrace_stackwalk.cpp b/backtrace_stackwalk.cpp index f271da44..d744877e 100644 --- a/backtrace_stackwalk.cpp +++ b/backtrace_stackwalk.cpp @@ -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 diff --git a/except.cpp b/except.cpp index 012a0178..d902c840 100644 --- a/except.cpp +++ b/except.cpp @@ -189,7 +189,7 @@ win32_error::code_string (DWORD code) code, MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), message, - elems (message), + std::size (message), NULL ); diff --git a/hash/md2.cpp b/hash/md2.cpp index 84c5d1b2..dcbedfc4 100644 --- a/hash/md2.cpp +++ b/hash/md2.cpp @@ -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; diff --git a/test/cmdopt.cpp b/test/cmdopt.cpp index d023ade0..12ad9229 100644 --- a/test/cmdopt.cpp +++ b/test/cmdopt.cpp @@ -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 ([&] () { @@ -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"); diff --git a/test/crypto/arc4.cpp b/test/crypto/arc4.cpp index 11c653e8..5bd072b6 100644 --- a/test/crypto/arc4.cpp +++ b/test/crypto/arc4.cpp @@ -16,7 +16,7 @@ main () struct { std::vector 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; diff --git a/test/crypto/tea.cpp b/test/crypto/tea.cpp index ab4bdca9..e7b3c4e6 100644 --- a/test/crypto/tea.cpp +++ b/test/crypto/tea.cpp @@ -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); diff --git a/test/crypto/xtea.cpp b/test/crypto/xtea.cpp index 17ca469f..25d1c448 100644 --- a/test/crypto/xtea.cpp +++ b/test/crypto/xtea.cpp @@ -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); diff --git a/test/crypto/xxtea.cpp b/test/crypto/xxtea.cpp index bb1faa92..a37827bc 100644 --- a/test/crypto/xxtea.cpp +++ b/test/crypto/xxtea.cpp @@ -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 ()); diff --git a/test/extent.cpp b/test/extent.cpp index 001b6ceb..cedd6301 100644 --- a/test/extent.cpp +++ b/test/extent.cpp @@ -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 (); diff --git a/test/float.cpp b/test/float.cpp index 7e9db339..0241baf3 100644 --- a/test/float.cpp +++ b/test/float.cpp @@ -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); diff --git a/test/hash/hmac.cpp b/test/hash/hmac.cpp index 089d8b28..c75afa6a 100644 --- a/test/hash/hmac.cpp +++ b/test/hash/hmac.cpp @@ -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 (); diff --git a/test/quaternion.cpp b/test/quaternion.cpp index 63b1948b..bcd89d4a 100644 --- a/test/quaternion.cpp +++ b/test/quaternion.cpp @@ -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 (); diff --git a/test/string.cpp b/test/string.cpp index 2c36c79d..883c577b 100644 --- a/test/string.cpp +++ b/test/string.cpp @@ -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); diff --git a/types.hpp b/types.hpp index 954ed66f..dcc5b512 100644 --- a/types.hpp +++ b/types.hpp @@ -22,19 +22,6 @@ #include #include -//----------------------------------------------------------------------------- -/// Returns the number of elements of a statically allocated array -template -constexpr size_t -elems (const T (&)[N]) - { return N; } - - -template -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