I have a structure with many "options", each of which, depending on its value, translates into a command-line option - either with or without a value. The order of the command-line options is of no consequence.
The detokenization is not always into a string, and the delimiter may not always be a character (it might actually be some functor object which manipulates the marshalled structure), so this needs to be templated code.
Right now, I have the following function:
template <typename MarshalTarget, typename Delimiter>
void process(const my_options_t& opts, MarshalTarget& marshalled, Delimiter optend)
{
if (opts.generate_relocatable_code) { marshalled << "--relocatable-device-code=true" << optend; }
if (opts.compile_extensible_whole_program) { marshalled << "--extensible-whole-program=true" << optend; }
if (opts.debug) { marshalled << "--device-debug" << optend; }
if (opts.generate_line_info) { marshalled << "--generate-line-info" << optend; }
if (opts.support_128bit_integers) { marshalled << "--device-int128" << optend; }
if (opts.indicate_function_inlining) { marshalled << "--optimization-info=inline" << optend; }
if (opts.compiler_self_identification) { marshalled << "--version-ident=true" << optend; }
if (not opts.builtin_initializer_list) { marshalled << "--builtin-initializer-list=false" << optend; }
if (opts.specify_language_dialect) {
marshalled << "--std=" << detail_::cpp_dialect_names[(unsigned) opts.language_dialect] << optend;
}
// etc. etc.
}
... but this has a problem: When MarshalTarget
is, say, an std::ostream
, and Delimiter
is a char
, I get a command-line fragment which ends in an extra space character. This isn't terrible, but I would rather avoid that extra space.
Would would be a good way to do so?