googletest icon indicating copy to clipboard operation
googletest copied to clipboard

[FR]: Make `Combine` generating custom types (CombineTo)

Open Stoorx opened this issue 8 months ago • 0 comments
trafficstars

Does the feature exist in the most recent commit?

I did not find that functionality.

Why do we need this feature?

It would be more handy to write:

struct MyStruct {
  int a;
  std::string b;
};

ParamGenerator<MyStruct> gen = CombineTo<MyStruct>(Values(1, 2, 3), Values("a", "b", "c"));

Than:

struct MyStruct {
  int a;
  std::string b;

  using TupleT = std::tuple<int, std::string>;

  MyStruct(const TupleT& t): a(std::get<0>(t)), b(std::get<1>(t)) {}
};

ParamGenerator<MyStruct> gen = ConvertGenerator<MyStruct::TupleT>(Combine(Values(1, 2, 3), Values("a", "b", "c")));

Describe the proposal.

Actually I have already developed it. https://github.com/google/googletest/pull/4727

In two words: I have introduced a new function CombineTo and refactored CartesianProductGenerator to support custom types instantiation.

Maybe it is better to rename to CombineAs.

Is the feature specific to an operating system, compiler, or build system version?

No

Stoorx avatar Feb 24 '25 18:02 Stoorx