stdtuple Questions
1
When examining the constructors of std::tuple on the cppreference site, I came across the move constructor defined below, which is available in C++23.
template< class... UTypes >
constexpr tu...
Hadrian asked 5/5 at 13:42
4
I need to alias std::get function in order to improve readability in my code.
Unfortunately I got a compile-time error get<0> in namespace ‘std’ does not name a type. using is equivalent to ...
1
Solved
I don't understand why in foobar below I need to specify std::vector<int>{} whereas in foobar2 I do not:
#include <iostream>
#include <memory>
#include <vector>
#include <...
Hydrotropism asked 30/9, 2023 at 0:56
24
Solved
How can I iterate over a tuple (using C++11)? I tried the following:
for(int i=0; i<std::tuple_size<T...>::value; ++i)
std::get<i>(my_tuple).do_sth();
but this doesn't work:
...
Stefanstefanac asked 29/7, 2009 at 5:57
6
Solved
In c++, how can I implement a function with an int template argument indicating the tuple length and produce a std::tuple with that length?
E.g.
func<2>() returns std::tuple<int, int>...
Caespitose asked 11/8, 2016 at 0:8
2
#include <iostream>
class NoCopyMove {
public:
NoCopyMove(int a) : a_(a), b_(a) {}
NoCopyMove(int a, int b) : a_(a), b_(b) {}
NoCopyMove(const NoCopyMove&) = delete;
NoCopyMove&...
2
Solved
The following code:
#include <tuple>
int main ()
{
auto f = [] () -> decltype (auto)
{
return std::get<0> (std::make_tuple (0));
};
return f ();
}
(Silently) generates code...
Ecg asked 20/12, 2017 at 11:45
3
Solved
After trying to make a std::get<N>(std::tuple) method myself, I'm not so sure how it's implemented by compilers. I know std::tuple has a constructor like this:
tuple(Args&&... args);
...
2
Solved
Here is the MWE:
#include <iostream>
#include <tuple>
#include <queue>
using namespace std;
bool operator<(tuple<int, int, int> lhs, tuple<int, int, int> rhs)
{
r...
3
Solved
While implementing a custom tuple (here), I found there is a wired swap() function that takes const parameters (cppreference):
template< class... Types >
constexpr void swap( const std::tuple...
2
Solved
Suppose I have the following class
class Example {
public:
using value_type = std::tuple<
uint8_t,
uint8_t,
uint16_t
>;
private:
value_type _value;
};
Now, I want to be able to create...
8
Solved
I want to use tuple consisting of int,char,char in my unordered_map. I am doing like this:
#include <string>
#include <unordered_map>
#include <cstring>
#include <iostream>...
Oloroso asked 30/12, 2013 at 7:0
1
Solved
I have a function f(), that returns a std::pair<A, B> with some types A and B. And I have another function g(), that calls f() twice and returns a std::tuple<A, B, A, B>. Is there a way...
1
Solved
The code as follows
#include <tuple>
int main()
{
auto [a] = std::make_tuple(1);
return [a]() -> int { return a; }();
}
produces an error in clang 12:
<source>:6:13: error: 'a'...
Bolanger asked 8/6, 2021 at 8:2
6
Solved
Is there a difference between an std::pair and an std::tuple with only two members? (Besides the obvious that std::pair requires two and only two members and tuple may have more or less...)
Quadrisect asked 14/7, 2011 at 0:9
3
I am writing a simple Entity Component System framework in which I want to use variadic templates to get more flexible interface. For each component I have offset (from the begining of chunk's memo...
Siana asked 16/3, 2021 at 19:8
3
To my surprise, I ran into another snag like C++20 behaviour breaking existing code with equality operator?.
Consider a simple case-insensitive key type, to be used with, e.g., std::set or std::map...
Gabriello asked 5/3, 2021 at 17:49
4
Solved
In reading this summary of the c++17 final features I was a bit surprised by the section on structured bindings (emphasis mine):
structured bindings
Until now, there was a known trick to abuse std...
Glossotomy asked 25/10, 2016 at 13:29
4
Solved
std::get does not seem to be SFINAE-friendly, as shown by the following test case:
template <class T, class C>
auto foo(C &c) -> decltype(std::get<T>(c)) {
return std::get<T...
Pew asked 17/1, 2017 at 22:53
2
Solved
I am currently learning metaprograming in C++, and I'm trying to see whether an element of a tuple is a pointer. I tried this approach:
int a = 3, b = 4;
auto tup = std::make_tuple(&a, b);
std:...
Oldham asked 11/10, 2020 at 7:22
2
C++ has a small-size struct calling convention optimization where the compiler passes a small-size struct in function parameters as efficiently as it passes a primitive type (say, via registers). F...
Foppish asked 3/9, 2020 at 7:58
5
Solved
This seems to be a very simple question: How does one remove the first (the n-th) type in a std::tuple?
Example:
typedef std::tuple<int, short, double> tuple1;
typedef std::tuple<short, ...
2
Solved
I would expect that in C++20 the following code prints nothing between prints of A and B (since I expect guaranteed RVO to kick in). But output is:
A
Bye
B
C
Bye
Bye
So presumably one temporary i...
Pronghorn asked 24/8, 2020 at 11:21
1
Solved
Consider:
std::tuple<bool, double, int> getTuple()
{
return {};
}
What does the standard say about the values in the resulting tuple in this case? Is it guaranteed that e.g. the bool is a...
4
Solved
I mean why does std::make_tuple exist? I know that there are situations where the function reduces the amount of characters you have to type because you can avoid template parameters. But is it the...
1 Next >
© 2022 - 2024 — McMap. All rights reserved.