c++ - Find out how this variadic templated function works -


in this answer have seen c++11 code, don't understand (but to).

there, variadic template function defined, (maybe?) takes arguments passed , inserts them std::ostringstream.

this function (see complete working example @ linked answer):

template<typename t, typename... ts> std::string createstring(t const& t, ts const&... ts) {     using expand = char[];      std::ostringstream oss;     oss << std::boolalpha << t;     (void)expand{'\0', (oss << ts, '\0')...};     return oss.str(); } 

when had guess, i'd say, character array created , initialized \0-bytes, , insertion of function's arguments stream happens side effect of initialization (part of comma expression). in end, array contains many nulls items inserted stream. it's casted void in order avoid compiler warning (unused variable). similar this:

char arr[] = {'\0', (oss << t1, '\0'), (oss << t2, '\0'), ..., (oss << tn, '\0')}; 

is attempt describe function's workings accurate? can explain design decision might relevant here, , why beneficial implement way (the alternative compile-time recursion, guess)?

after receiving helpful hints in question's comment section figure out of points:


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -