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...

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_...

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&...

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 ...

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...

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...

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...

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...

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...

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...

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...

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.