From 408ee1da67f69039a0c65881341bc381395e9eff Mon Sep 17 00:00:00 2001 From: Pawel Kurowski Date: Fri, 6 Sep 2019 18:54:40 +0200 Subject: [PATCH] Add ByteVector::Create --- Src/Common/MWR/CppTools/ByteVector.h | 31 +++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/Src/Common/MWR/CppTools/ByteVector.h b/Src/Common/MWR/CppTools/ByteVector.h index 3710b7c..10363a3 100644 --- a/Src/Common/MWR/CppTools/ByteVector.h +++ b/Src/Common/MWR/CppTools/ByteVector.h @@ -69,7 +69,6 @@ namespace MWR return *this; } - /// Write content of of provided objects. /// Suports arithmetic types, std::string, std::wstring, std::string_view, std::wstring_view, ByteVector and ByteArray, and std::tuple of those types. /// Do not write header with size for types that can have undefined buffer.. Recipient must know size in advance to read, therefore should use Read>. @@ -82,6 +81,36 @@ namespace MWR return *this; } + /// Create new ByteVector with Variadic list of parameters. + /// This function cannot be constructor, becouse it would be ambigious with std::vector costructors. + /// @see ByteVector::Write and ByteVector::Concat for more informations. + template ::value, int> = 0> + static ByteVector Create(T... args) + { + if constexpr (preferWriteOverConcat) + return CreateByWrite(args...); + else + return CreateByConcat(args...); + } + + /// Create new ByteVector with Variadic list of parameters. + /// This function cannot be constructor, becouse it would be ambigious with std::vector costructors. + /// @see ByteVector::Write for more informations. + template ::value, int> = 0> + static ByteVector CreateByWrite(T... args) + { + return ByteVector{}.Write(args...); + } + + /// Create new ByteVector with Variadic list of parameters. + /// This function cannot be constructor, becouse it would be ambigious with std::vector costructors. + /// @see ByteVector::Concat for more informations. + template ::value, int> = 0> + static ByteVector CreateByConcat(T... args) + { + return ByteVector{}.Concat(args...); + } + // Enable methods. using Super::vector; using Super::value_type;