Features: Add cxx_variadic_templates.

Expect cxx_variadic_templates to implement N2555.

N2555 is essentially a bugfix and predates most compiler releases which
aimed to experimentally support variadic templates.
This commit is contained in:
Stephen Kelly 2014-04-02 15:02:41 +02:00
parent 750dfee29c
commit 10f33eee1d
4 changed files with 85 additions and 1 deletions

View File

@ -21,3 +21,8 @@ The features known to this version of CMake are:
Delegating constructors, as defined in N1986_.
.. _N1986: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n1986.pdf
``cxx_variadic_templates``
Variadic templates, as defined in N2242_.
.. _N2242: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2242.pdf

View File

@ -5,7 +5,20 @@ set(_oldestSupported "(__GNUC__ * 100 + __GNUC_MINOR__) >= 408")
# TODO: Should be supported by GNU 4.7
set(GNU47_CXX11 "${_oldestSupported} && __cplusplus >= 201103L")
set(_cmake_feature_test_cxx_delegating_constructors "${GNU47_CXX11}")
# NOTE: C++11 was ratified in September 2011. GNU 4.7 is the first minor
# release following that (March 2012), and the first minor release to
# support -std=c++11. Prior to that, support for C++11 features is technically
# experiemental and possibly incomplete (see for example the note below about
# cxx_variadic_template_template_parameters)
# TODO: Should be supported by GNU 4.4
set(GNU44_CXX11 "${_oldestSupported} && __cplusplus >= 201103L")
set(_cmake_feature_test_cxx_auto_type "${GNU44_CXX11}")
set(_cmake_feature_test_cxx_variadic_templates "${GNU44_CXX11}")
# TODO: If features are ever recorded for GNU 4.3, there should possibly
# be a new feature added like cxx_variadic_template_template_parameters,
# which is implemented by GNU 4.4, but not 4.3. cxx_variadic_templates is
# actually implemented by GNU 4.3, but variadic template template parameters
# 'completes' it, so that is the version we record as having the variadic
# templates capability in CMake. See
# http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2555.pdf
set(_oldestSupported)

View File

@ -43,7 +43,8 @@
#define FOR_EACH_CXX_FEATURE(F) \
F(cxx_auto_type) \
F(cxx_delegating_constructors)
F(cxx_delegating_constructors) \
F(cxx_variadic_templates)
class cmMakefile::Internals
{

View File

@ -0,0 +1,65 @@
template<int I, int... Is>
struct Interface;
template<int I>
struct Interface<I>
{
static int accumulate()
{
return I;
}
};
template<int I, int... Is>
struct Interface
{
static int accumulate()
{
return I + Interface<Is...>::accumulate();
}
};
// Note: split this into a separate test if a
// cxx_variadic_template_template_parameters feature is added.
template<typename T>
struct eval {
enum {
Matched = 0
};
};
template<template<typename...> class T, typename... U>
struct eval<T<U...> > {
enum {
Matched = 1
};
};
template<typename...>
struct A {
};
template<typename T>
struct B {
};
template<typename T, typename U>
struct C {
};
template<typename T, typename U, typename...>
struct D {
};
// Note: This test assumes that a compiler supporting this feature
// supports static_assert. Add a workaround if that does not hold.
static_assert(eval<A<> >::Matched, "A Matches");
static_assert(eval<A<int> >::Matched, "A Matches");
static_assert(eval<A<int, char> >::Matched, "A Matches");
static_assert(eval<B<int> >::Matched, "B Matches");
static_assert(eval<C<int, char> >::Matched, "C Matches");
static_assert(eval<D<int, char> >::Matched, "D Matches");
static_assert(eval<D<int, char, bool> >::Matched, "D Matches");
static_assert(eval<D<int, char, bool, double> >::Matched, "D Matches");