non-type-template-parameter Questions
2
Solved
In C++ Weekly - Ep 313 - The constexpr Problem That Took Me 5 Years To Fix!, Jason Turner demonstrates several compile-time techniques in order to construct a std::string at compile-time and then p...
Clint asked 29/2, 2024 at 14:29
1
Solved
Consider this code:
#include <type_traits>
template <typename T>
struct wrapper {
T& ref;
constexpr wrapper(T& ref) : ref(ref) {}
};
// Trait that checks whether a type is o...
Hilaire asked 6/1, 2024 at 7:2
1
Solved
Somehow I still think of lambdas as "syntactic sugar" for regular function objects, so it surprises me that under C++-20 a stateful but otherwise constexpr lambda instance cannot be...
Nesta asked 23/11, 2023 at 11:51
7
Solved
I am working with a library which exposes an interface to work with. One of the functions of this library is like this :
template <int a>
void modify(){}
I have to modify parameters from 1 t...
Lifesize asked 18/6, 2012 at 11:9
5
Solved
When declaring a template, I am used to having this kind of code:
template <class T>
But in this question, they used:
template <unsigned int N>
I checked that it compiles. But wha...
Childs asked 31/1, 2009 at 16:27
1
Solved
I have this class
template <typename ValueType, std::size_t Size>
struct ArrayPrimitive
{
constexpr ArrayPrimitive(const ValueType (&array)[Size]) {
std::copy(array, array + Size, data_...
Chasidychasing asked 3/9, 2023 at 14:29
2
Solved
Why this application doesn't compile?
#include <iostream>
#include <array>
template<int N>
std::ostream& operator << (std::ostream& out, std::array<int, N&...
Fanfani asked 9/1, 2023 at 8:21
1
template<template<auto> class> struct A {};
template<int&> struct B {};
A<B> a;
int main() {}
All three compilers MSVC, GCC and Clang in their latest versions accept ...
Speiss asked 23/12, 2022 at 0:17
1
#include<type_traits>
template <typename T, T>
struct A { };
template <typename T, T t>
void f(A<T, t>) {
}
int main() {
f(A<const int, 0>{});
}
https://godbolt.o...
Geochronology asked 11/2, 2022 at 23:51
1
In my previous question (Is it legal to use an unexpanded parameter pack as the type of a template template parameter's non-type template parameter?), it was pointed out that it is not legal to...
Bebebebeerine asked 13/3, 2022 at 13:34
0
Suppose we have the following program:
template <class T, T n1, T n2>
struct Probe {
static const int which = 1;
};
template <class T, T n>
struct Probe<T, n, n> {
static con...
Denny asked 7/2, 2022 at 16:54
2
Solved
msvc compiles the following code(with /permissive- compiler switch), clang and gcc do not:
template<auto val>
struct S{
static constexpr auto val = val;
};
int main() {
return S<4>::v...
Skill asked 9/8, 2021 at 13:32
4
Solved
Assume I want to define types that are similar in structure, but differ in a parameter that could be an integer or could be something else.
Is it possible in Java to define a family of classes para...
Eugene asked 4/8, 2021 at 14:28
0
In C++20, I defined a concept AllIntegral with a non-type template parameter pack auto... T_values.
Whilst, GCC 10.1.0 accepts its usage in some contexts, it refuses to compile its usage in others,...
Hyrup asked 19/12, 2020 at 16:30
3
Solved
I am learning concepts, and I can not figure out a way to restrain the value (not type) of non-type template parameter.
Example of code that compiles, although I wish it did not(due to failed requi...
Rode asked 16/11, 2020 at 12:42
1
Solved
Concepts can be used to put a constraint on types as template parameters like the example below:
template<typename t, int v>
concept the_concept1 = sizeof(t) > v;
template<int v, the_c...
Misjoinder asked 18/9, 2020 at 8:45
4
Solved
I would like to use a template class to provide some common functionality to some child classes that are very similar. The only variation is the enumeration that each uses.
This is the parent cla...
Jehad asked 2/2, 2012 at 16:45
2
Solved
how would you go about using non-type template parameter comparison in a std::enable_if?
I can not figure out how to do this again. (I once had this working, but I lost the code so I can't lo...
Fug asked 18/5, 2013 at 1:41
4
Solved
I understand that non-type template parameters should be a constant integral expression. Can someone shed light why this is so?
template <std::string temp>
void foo()
{
// ...
}
error C299...
Diplomate asked 16/4, 2011 at 15:32
1
© 2022 - 2025 — McMap. All rights reserved.