non-type Questions

4

Solved

If we have a template function which takes a non-type parameter of type int or short the compiler complains about the ambiguity of the following call: // Definition template <int I> void foo...
Affirmation asked 5/3, 2015 at 10:57

4

Solved

According to the reference, the name of a non-type template parameter is optional, even when assigning a default value (see (1) and (2)). Therefore these template structs are valid: template <i...
Oro asked 20/1, 2020 at 14:1

2

Consider the following structure: S is a class template with a variadic pack of template type parameters ...Ts. The class contains a nested class template N, which has a single template template pa...
Dalhousie asked 26/11, 2020 at 3:12

2

Solved

Consider this code: using func = int (*)(int, int); template<func F> void do_something(int first, int second) {} int something(int first, int second) { return 42; } void f() { constexpr a...
Petition asked 30/11, 2020 at 16:54

1

Solved

Consider the following class S containing a function pointer, and a constexpr object s of that class initialized with a lambda: struct S { void (*f) (); }; constexpr S s { []{} }; Now if I wr...
Hagio asked 3/11, 2020 at 2:24

1

Solved

I am reading again "C++ Primer, 5th edition". In chapter 16 about templates, there is an example of "template Non-type parameters": template<unsigned N, unsigned M> int co...
Urinary asked 22/10, 2020 at 18:11

0

For the following code: template<class... Parameter> struct Outer { template<Parameter... Value> struct Inner { static bool Member; }; }; template<class... Parameter> templat...
Kilkenny asked 31/8, 2020 at 14:25

3

Solved

Is the following code legal? template <auto Lambda> struct A {}; int main () { auto lmb = [](int i){return i*i;}; A<lmb> a; return 0; } I noticed that g++ compiles it fine,...
Basal asked 11/6, 2020 at 12:7

1

Solved

I am unsure whether this is a compiler bug, or whether I have done something that goes against the standard to cause undefined behaviour. Here is my code: #include <iostream> template<aut...
Depersonalize asked 4/7, 2019 at 11:5

3

Solved

I'm a bit confused about partial template specialization... I have some code that depends on an arithmetic data type T, and on a small integer DIM. I want to be able to specify different class meth...
Crayton asked 19/12, 2017 at 2:28

2

Solved

I am trying to achieve the following: template<template<typename> bool Function_, typename ... Types_> constexpr auto find(Tuple<Types_ ... >) noexcept { // ... } where a pos...
Scuttle asked 12/7, 2017 at 4:9

3

Solved

Let's say I have two structs, Foo and Bar: template<int...> struct Foo{}; template<unsigned long...> struct Bar{}; I want to create a type trait (call it match_class) that returns t...
Winshell asked 30/5, 2017 at 13:21

2

Solved

The following snippet compiles with no error with Clang 4.0 but GCC 7.0 produces errors (note the use of -std=c++1z flag). using FuncT = int (*)(double); template <FuncT FUNC> int temp_foo...
Misbelief asked 4/4, 2017 at 17:34

1

Solved

Consider an example: #include <type_traits> template <class T, T> struct has_duplicates_info { }; template <class T, T...> struct has_duplicates; template <class T, T First...
Complexioned asked 31/8, 2016 at 15:24

1

Solved

I have read many questions and answers, but this question caught my eye the most; it and its answers are helpful but I still feel that I do not fully understand the uses and the theories behi...
Rouge asked 8/7, 2016 at 15:49

2

Solved

I have the following non-type template: template<size_t MAX_SIZE> struct Path{ struct Point{ float x; float y; } }; Point segment[MAX_SIZE]; }; If I now declare two different Paths, ...
Pteridophyte asked 6/4, 2016 at 14:38

5

Section 4.3 of C++ Templates states 'Not being able to use floating-point literals (and simple constant floating-point expressions) as template arguments has historical reasons.' Similarly...
Prae asked 27/9, 2010 at 3:13

2

Solved

Why is it that the template argument of a non-type reference cannot be another reference (g++ 4.8.1): template <int& N> void test() { } int x = 5; int& p = x; int main(){ test<...
Foreyard asked 23/10, 2015 at 11:46

3

Solved

In the C++ template terminology we have non-type template parameters, type template parameters, and template template parameters (and then the same list with arguments). Why is it called non-type?...
Styracaceous asked 11/11, 2014 at 9:43

4

Solved

Maybe I'm tired, but I'm stuck with this simple partial specialization, which doesn't work because non-type template argument specializes a template parameter with dependent type 'T': template &lt...
Belindabelisarius asked 18/3, 2014 at 17:13

3

Solved

First of all, I'm sorry for the vague title of this question. I wasn't sure how to summarize it. The thing I want to achieve is the following, I want to be able to pass template non-type paramete...
Plano asked 10/1, 2014 at 16:24

1

Solved

C++ allows non-type template parameters to be of pointer, including function pointer, type. I recently asked a question about what this is useful for, and this is a follow up to one of the answers....
Changchangaris asked 19/7, 2013 at 0:41

1

The following program compiles without errors or warning with gcc 4.8.1, -Wall -std=c++11: template<unsigned N> struct A{}; int main(){ A<1-2> a; (void)a; return 0; } clang 3.3 w...
Tormentor asked 9/7, 2013 at 22:8

5

Solved

C++ allows non-type template parameters to be of integral or enumeration type (with integral including boolean and character), as well as pointers and references to arbitrary types. I have seen in...
Emcee asked 3/3, 2013 at 21:27

1

Solved

I'm having difficulty defining and specializing a member function update() of an inner class Outer<T1>::Inner that is templated on a non-type (enum) argument. #include <cstdlib> templ...
Jaynejaynell asked 8/2, 2013 at 16:9

© 2022 - 2024 — McMap. All rights reserved.