view: char constructor shouldn't include null characters
This commit is contained in:
parent
14d3169c26
commit
dc51fa2ed0
@ -10,6 +10,11 @@ main (int, char**)
|
||||
{
|
||||
util::TAP::logger tap;
|
||||
|
||||
tap.expect_eq (
|
||||
std::size (util::make_view ("foo")), 3u,
|
||||
"character array view does not include trailing null"
|
||||
);
|
||||
|
||||
const std::string s = "this is a test string";
|
||||
const std::string t = "not the same string";
|
||||
|
||||
|
10
view.hpp
10
view.hpp
@ -46,6 +46,16 @@ namespace util {
|
||||
{ ; }
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// explicitly cater for the char array case so that we don't
|
||||
// accidentally include the trailing null in the data.
|
||||
template <std::size_t N>
|
||||
view (const char (&value)[N]):
|
||||
view (std::begin (value), std::begin (value) + N - 1)
|
||||
{
|
||||
static_assert (N > 0);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
template <std::size_t N, typename ValueT>
|
||||
view (const ValueT(&value)[N]):
|
||||
|
Loading…
Reference in New Issue
Block a user