encoding+lp+net: simplify with `if constexpr`
Change-Id: Ie2b45a502c59e5cb7181628e691f7aaaf7509d84
diff --git a/tests/unit/encoding/block.t.cpp b/tests/unit/encoding/block.t.cpp
index f75eaf0..8dd21d3 100644
--- a/tests/unit/encoding/block.t.cpp
+++ b/tests/unit/encoding/block.t.cpp
@@ -169,7 +169,7 @@
BOOST_CHECK_EQUAL(b3.isValid(), false);
BOOST_CHECK_EQUAL(b3.type(), tlv::Invalid);
BOOST_CHECK_EXCEPTION(b3.size(), Block::Error, [] (const auto& e) {
- return e.what() == "Cannot determine size of invalid block"s;
+ return e.what() == "Cannot determine size of invalid block"sv;
});
BOOST_CHECK_EQUAL(b3.hasValue(), false);
BOOST_CHECK_EQUAL(b3.value_size(), 0);
@@ -253,7 +253,7 @@
BOOST_CHECK(stream.eof());
BOOST_CHECK_EXCEPTION(Block::fromStream(stream), tlv::Error, [] (const auto& e) {
- return e.what() == "Empty buffer during TLV parsing"s;
+ return e.what() == "Insufficient data during TLV parsing"sv;
});
}
@@ -315,7 +315,7 @@
BOOST_CHECK(b3.value() == nullptr);
BOOST_CHECK_EXCEPTION(Block::fromStream(stream), tlv::Error, [] (const auto& e) {
- return e.what() == "Empty buffer during TLV parsing"s;
+ return e.what() == "Insufficient data during TLV parsing"sv;
});
}
@@ -331,7 +331,7 @@
stream.seekg(0);
BOOST_CHECK_EXCEPTION(Block::fromStream(stream), tlv::Error, [] (const auto& e) {
- return e.what() == "TLV-LENGTH from stream exceeds limit"s;
+ return e.what() == "TLV-LENGTH from stream exceeds limit"sv;
});
}
@@ -447,12 +447,12 @@
{
Block b1(301);
BOOST_CHECK_EXCEPTION(b1.blockFromValue(), Block::Error, [] (const auto& e) {
- return e.what() == "Cannot construct block from empty TLV-VALUE"s;
+ return e.what() == "Cannot construct block from empty TLV-VALUE"sv;
});
Block b2(302, std::make_shared<Buffer>());
BOOST_CHECK_EXCEPTION(b2.blockFromValue(), Block::Error, [] (const auto& e) {
- return e.what() == "Cannot construct block from empty TLV-VALUE"s;
+ return e.what() == "Cannot construct block from empty TLV-VALUE"sv;
});
b1.encode();
@@ -491,7 +491,7 @@
BOOST_CHECK(data.get(0x15) == data.elements().at(2));
BOOST_CHECK_EXCEPTION(data.get(0x01), Block::Error, [] (const auto& e) {
- return e.what() == "No sub-element of type 1 found in block of type 6"s;
+ return e.what() == "No sub-element of type 1 found in block of type 6"sv;
});
BOOST_CHECK(data.find(0x15) == data.elements_begin() + 2);
@@ -503,7 +503,7 @@
};
Block bad(MALFORMED);
BOOST_CHECK_EXCEPTION(bad.parse(), Block::Error, [] (const auto& e) {
- return e.what() == "TLV-LENGTH of sub-element of type 7 exceeds TLV-VALUE boundary of parent block"s;
+ return e.what() == "TLV-LENGTH of sub-element of type 7 exceeds TLV-VALUE boundary of parent block"sv;
});
}
diff --git a/tests/unit/encoding/tlv.t.cpp b/tests/unit/encoding/tlv.t.cpp
index 5eaa17a..9cd7cc4 100644
--- a/tests/unit/encoding/tlv.t.cpp
+++ b/tests/unit/encoding/tlv.t.cpp
@@ -59,11 +59,9 @@
using StreamIterator = std::istream_iterator<uint8_t>;
#define ASSERT_READ_NUMBER_IS_FAST(T) \
- static_assert(std::is_base_of_v<detail::ReadNumberFast<T>, detail::ReadNumber<T>>, \
- # T " should use ReadNumberFast")
+ static_assert(detail::IsContiguousIterator<T>, #T " is not fast")
#define ASSERT_READ_NUMBER_IS_SLOW(T) \
- static_assert(std::is_base_of_v<detail::ReadNumberSlow<T>, detail::ReadNumber<T>>, \
- # T " should use ReadNumberSlow")
+ static_assert(!detail::IsContiguousIterator<T>, #T " is not slow")
ASSERT_READ_NUMBER_IS_FAST(const uint8_t*);
ASSERT_READ_NUMBER_IS_FAST(uint8_t*);
@@ -80,6 +78,8 @@
ASSERT_READ_NUMBER_IS_FAST(Uint8Array::iterator);
using CharArray = std::array<char, 87>;
ASSERT_READ_NUMBER_IS_FAST(CharArray::iterator);
+ASSERT_READ_NUMBER_IS_FAST(span<const uint8_t>::iterator);
+ASSERT_READ_NUMBER_IS_FAST(span<uint8_t>::iterator);
ASSERT_READ_NUMBER_IS_FAST(std::string::const_iterator);
ASSERT_READ_NUMBER_IS_FAST(std::string::iterator);
ASSERT_READ_NUMBER_IS_FAST(Buffer::const_iterator);