template-instantiation Questions
2
The code in this question is based on this answer. I am a little confused about how this produces the output it does, and whether it is all well defined
#include <type_traits>
#include <io...
Shiri asked 10/8, 2022 at 15:30
1
Solved
Is use in a default member initializer still an odr-use, even if the default member initializer is not used by any constructor?
For example, is this program ill-formed because g<A> is odr-use...
Navigable asked 9/3, 2022 at 11:36
1
This is a follow up of this question: Does PIMPL idiom actually work using std::unique_ptr?
The full example uses multiple files, so for the sake of this question I will reduce it here. The full wo...
Placeman asked 8/3, 2022 at 15:27
2
Solved
The fact that a template is not instantiated until it is used so for example if I have this class template:
template <typename T>
struct Pow{
T operator()(T const& x) const{ return x * x...
Ensor asked 20/10, 2021 at 20:20
1
Solved
Here is an exercise from C++ primer 5th edition:
"Exercise 16.26: Assuming NoDefault is a class that does not have a default constructor, can we explicitly instantiate vector<NoDefault>?...
Revealment asked 12/11, 2020 at 21:39
1
This codes run on G++, but not on Visual C++.
#include <iostream>
template<typename T> void foo( T& t,int some_parameter){}
template decltype(foo<int>) foo;
int main(){
std::...
Decigram asked 21/9, 2020 at 9:31
0
It used to be possible, using some C++ compilers, to check whether a templated type has already been instantiated, so that the following program syntax compiles without error:
template <typenam...
Middlesworth asked 3/4, 2020 at 14:29
2
Solved
I have a problem; I want to explicitly instantiate a class like Datatype in:
using Layout = some::namespaces::Meat_Layout<Some,Parameters>;
using Datatype = other::namespaces::Meta_Datatype&l...
Cazzie asked 7/11, 2019 at 9:19
4
I want to force template instantiation.
The below code works (print 1) at g++ ( http://coliru.stacked-crooked.com/a/33986d0e0d320ad4 ).
However, it prints wrong result (0) at Visual C++ ( https://r...
Gurdwara asked 16/9, 2019 at 9:7
1
Solved
Looking at libstdc++ source code, I found the following declval implementation:
template<typename _Tp, typename _Up = _Tp&&>
_Up __declval(int); // (1)
template<typename _Tp>
...
Turfy asked 19/5, 2019 at 21:23
1
Solved
[temp.spec]/6 reads:
The usual access checking rules do not apply to names in a declaration of an explicit instantiation or explicit specialization, with the exception of names appearing in a fu...
Substrate asked 14/1, 2019 at 2:17
1
Solved
Assume I have the following code snippet:
template <class T>
class Bar
{
// static_assert(sizeof(T) > 0); // (1)
public:
void method()
{
static_assert(sizeof(T) > 0); // (2)
}
};
...
Springspringboard asked 1/1, 2019 at 17:50
1
Solved
I'm trying to understand if constexpr fully.
I understand, that if if constexpr(expr) used in a template, and expr is dependent on a template parameter, then during instantiation, only one of the ...
Revere asked 2/12, 2018 at 23:28
1
Solved
The following code (I couldn't make a shorter MVCE)
unit.h:
#include <vector>
template<typename T>
struct foo
{
std::vector<T> data;
foo(foo&&) = default; // no assem...
Mystify asked 13/11, 2018 at 14:17
1
Solved
I expect the following to be ill formed NDR, but it seems not :-(
#include <type_traits>
template <typename T, typename Enabler = void>
struct is_complete : std::false_type {};
templ...
Nitrification asked 10/9, 2018 at 20:24
1
The question in the title is clear enough. To be more specific, consider the following example:
#include <type_traits>
template <typename T>
struct is_complete_helper {
template <...
Rusticus asked 6/9, 2018 at 9:39
4
Solved
Consider this code:
template <typename T>
class A {
T x;
// A bunch of functions
};
std::size_t s = sizeof(A<double>);
Assume the sizeof operator is the only place where an instan...
Killer asked 30/12, 2017 at 10:10
1
Solved
Say I have a template class defined like this
template <typename T>
class Temp{
// irrelevant
};
I can either implicitly or explicitly instantiate it:
Temp<int> ti;
template class ...
Marino asked 5/10, 2017 at 3:12
2
Solved
Consider the following code. Is it guaranteed that Derived<int>::foo() will be instantiated? foo() is virtual and is called by a non-virtual function of the base class.
#include <iostream...
Khabarovsk asked 15/12, 2016 at 22:12
2
Solved
Suppose I have
template <bool UsesFastMath> void foo(float* data, size_t length);
and I want to compile one instantiation with -ffast-math (--use-fast-math for nvcc), and the other instan...
Coincident asked 19/11, 2016 at 23:34
1
Solved
This code is from "C++ programming language" by Bjarne Stroustrup (C.13.8.3 Point of Instantiation Binding)
template <class T>
void f(T value)
{
g(value);
}
void g(int v);
void h()
{
ext...
Coltish asked 10/10, 2016 at 13:9
2
Solved
Using GCC 4.8.4 with g++ --std=c++11 main.cpp outputs the following error
error: unable to deduce ‘auto’ from ‘max<int>’
auto stdMaxInt = std::max<int>;
for this code
#include <a...
Sept asked 14/11, 2015 at 7:15
1
© 2022 - 2024 — McMap. All rights reserved.