Instead of a template that supports up to 10 arguments.
Details
Diff Detail
Event Timeline
Looks good to me. Optional generalization of the metaprogramming if you like.
(actually, could even be generalized further by taking the test functor (max, min, etc) as another template parameter, I suppose)
include/llvm/Support/AlignOf.h | ||
---|---|---|
233–243 | Could potentially generalize the two variadic impls to take the non-variadic as a trait, if you like? template<template Trait<typename>, typename T, typename... Ts> struct Max { enum { X = Trait<T>::value, Y = Max<Trait, Ts...>::value, value = (X > Y) ? X : Y }; }; template<template Trait<typename>, typename T> struct Max<Trait, T> { enum { value = Trait<T>::value; }; }; template<typename T> struct SizeOf { enum { value = sizeof(T) }; }; template<typename T> struct AlignOf { enum { value = alignof(T) }; }; ... Max<SizeOf, Ts...>::value Max<AlignOf, Ts...>::value |
That's interesting, but I think I wouldn't generalize it that much since we only have two templates here. If we have more that would be useful though.
- Make AlignOf to take more than one arguments since there is another place that does the same thing.
include/llvm/Support/AlignOf.h | ||
---|---|---|
61–65 | What's the need for this separate helper rather than the usual variadic template recursion+base case below? | |
88 | I'm not sure we want to generalize the fundamental traits like this over variadic arguments & at this point would be a little more in favor of separating the variadic/max behavior from the basic trait. I don't insist on it, but wouldn't mind a 3rd opinion as it were (but I don't insist on that either). Maybe it does make sense to just make lots of traits inherently variadic if there's a single logical composition? (max rather than min, or sum, or anything else) |
What's the need for this separate helper rather than the usual variadic template recursion+base case below?