view: char constructor shouldn't include null characters

This commit is contained in:
Danny Robson 2017-12-26 17:29:32 +11:00
parent 14d3169c26
commit dc51fa2ed0
2 changed files with 15 additions and 0 deletions

View File

@ -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";

View File

@ -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]):