All Questions
Tagged with forwarding c++
42
questions
0
votes
1
answer
97
views
How to use a non-template function to achieve perfect forwarding by an argument-wise manner?
template<typename T> class Group;
template<typename...U>
class Group<std::tuple<U...>> {
public:
typedef std::tuple<U...> type;
void emplace_back(U&......
2
votes
0
answers
62
views
If I pass an rvalue into a function with T&&, in some cases I can change the value, in other cases I can't, why? [duplicate]
#include <iostream>
void g(int&) {
std::cout << "int&" << std::endl;
}
void g(int&&) {
std::cout << "int&&" << std::...
0
votes
1
answer
155
views
calling perfectly forwarded lambda
I have the following class which stores a perfectly forwarded reference to a function:
template <class F>
class Visitor
{
public:
Visitor(F &&f) : _f(std::forward<F>(f))
{...
2
votes
2
answers
364
views
Can you perfectly forward without templates
I have a class that has multiple constructors:
class Obj
{
public:
Obj(int x, int y) {}
Obj(std::string const& str) {}
Obj(char v, int s) {}
};
Now ...
0
votes
0
answers
60
views
Perfect Forwarding and move
I have a program where i have a struct with 2 data members
struct myStruct{
uint64_t promotionID;
int32_t amount;
};
I have to add them to an unordered_map where i had ...
0
votes
1
answer
391
views
Can modern C++ compilers optimise the assignment operator for temporary variables?
Below is MyStruct class implementation which has default and copy constructors.
struct MyStruct {
MyStruct(const string& name) {
cout << "Basic constructor called" <&...
2
votes
2
answers
97
views
Only allow access to an object's members, not the object itself
Given the following class:
class Foo
{
public:
//...
private:
Bar mBar;
};
Is it possible to expose the mBar member in such a way that it's members can be accessed, but not the mBar ...
28
votes
3
answers
3k
views
Why use std::forward<T> instead of static_cast<T&&>
When given code of the following structure
template <typename... Args>
void foo(Args&&... args) { ... }
I've often seen library code use static_cast<Args&&> within the ...
0
votes
1
answer
759
views
Forwarding Kamailio SIP message to a C application
I'm using Kamailio as a SIP server, and I want to forward the SIP message to a C++ application. I've been looking at SIP modules to do this but the documentation is not completely clear and there aren'...
3
votes
1
answer
1k
views
Simulating std::forward with std::forward_as_tuple
Let's say I use std::forward_as_tuple to store the arguments of a function call in a tuple
auto args = std::forward_as_tuple(std::forward<Args>(args)...);
And then I pass this tuple by lvalue ...
5
votes
1
answer
289
views
Gotchas with template argument deduction for class templates
I was reading the paper regarding template argument deduction for class templates here http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0091r3.html. This feature is in the C++17 standard, and ...
3
votes
1
answer
81
views
Using std::forward with a forwarding reference
Is this function
template< typename T >
void foo( T&& in )
{
bar( std::forward<T>( in ) );
}
equivalent to
template< typename T >
void foo( T&& in )
{
bar( std:...
5
votes
1
answer
922
views
Identity function with perfect forwarding
I want to write a function identity which perfectly forwards its argument without any copy. I would write something like this
template< typename V >
inline V&& identity( V&& v ...
0
votes
1
answer
808
views
Use a child function in a parent class cpp
I have a parent class and a child class where the parent class uses one of the child classes in one of the parent's methods. In this method the parent uses the constructor and a method (that is a ...
0
votes
1
answer
101
views
How to be able to move data out of scope using default move constructor?
I want to move data into other scope. And it seems to work... yet destructor of an object seems to crush application with runtime exception:
#include <iostream>
using namespace std;
struct A {
...