New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Template apply #203
Template apply #203
Conversation
I changed it to be against the dev branch instead of master and resolved some conflicts. Thanks for the patch! I'm thinking about this right now. |
Oh, Here is a code snippet to show how we use it: In library header: using implementations =
std::conditional_t<kHaveBLAS, std::tuple<blas, simd>, std::tuple<simd>>; In tests, which can also be in library code since this is doctest :) TEST_CASE_TEMPLATE_DEFINE("math op1", T, test_math_op1) {
...
c.Build<T>()
...
}
TEST_CASE_TEMPLATE_APPLY(test_math_op1, implementations); So basically, the current |
So if this gets accepted - the implementation will be relying on a tuple. What other ways are there in modern C++ to express type lists at compile time? I'm just cautious before closing this door and committing to Also I'll change it to a vararg macro after I merge it so you don't need a typedef (or "using") before the macro call (because of the commas in between the <> of the tuple) EDIT: Perhaps any sane C++ type list can be translated to a tuple so I need not worry. |
@zhihaoy do you think it's possible to make Perhaps detecting if what is passed is a tuple, in which case to not wrap it further in a tuple? Or how would you feel about this name: EDIT: I'm actually going ahead and renaming it. |
In practice, it is trivial for user to transform their type list into The standard library doesn't define a About the naming, if have a chance, I would like to have it changed back to |
Both are needed. Here is the metaphor I use to explain: |
Well in that case I would want to rename INSTANTIATE to INVOKE and keep a Oh god - why does naming have to be such a time sink :D EDIT: I'll move back to "APPLY" |
Description
TEST_CAST_TEMPLATE_INSTANTIATE
is nice, but doesn't work for computed type lists. Here we just use predeclaredstd::tuple
as a type list, and add a new macroTEST_CAST_TEMPLATE_APPLY
to instantiate those types.Our need for this feature is strong. It's not only useful in testing generic code, but also useful in testing different implementations for type-erased interface. The list of types with expected semantics in the first case and the list of available classes for implementations varies from build to build on different platforms, etc.