Skip to main content

All Questions

Tagged with
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" <&...
mercury0114's user avatar
  • 1,439
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 ...
Curious's user avatar
  • 21.3k
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 ...
Marco Agnese's user avatar
5 votes
2 answers
315 views

Selective forwarding function

The task is to create a single-argument function that forwards all types apart from one (Foo), which it converts (to Bar). (Let us assume there exists a conversion from Foo to Bar). Here is the usage ...
P i's user avatar
  • 30.1k
0 votes
1 answer
215 views

C func to C++ instance-member trampoline with non-bijective argument type mapping

EDIT: I think I have cracked it, here (Non bijective here means we may have arguments of type const char or char* both mapping to const std::string&.)* NOTE: I've been working at this and asking ...
P i's user avatar
  • 30.1k
1 vote
1 answer
731 views

Perfect forwarding for wrapper classes

I have for example a wrapper class: template <typename T> struct Wrapper { T t; }; And some proxy class that takes does something with T: template <typename T> struct Proxy { T ...
user avatar
1 vote
1 answer
1k views

C++: Forwarding the sum of parameter pack and a std::tuple/array [duplicate]

I want to implement something like the following member function (method), which is supposed to increase each argument by some summand (addend) corresponding to the argument index and forward it to ...
eold's user avatar
  • 6,022
5 votes
3 answers
294 views

Is a C++ template able to "forward any class function" from parent class?

class Foo { public: void methodA(); }; class ManagedFoo { Foo fooInst; public: void methodA() { doSomething(); fooInst.methodA();} }; Now I want to make ManagedFoo as a template, managing any ...
Rayer's user avatar
  • 67
1 vote
0 answers
541 views

C++ master/slave register model

I'm looking forward to implement a master/slave register model template for any type in C++. I've started with: template <typename T> struct Reg { Reg() {} Reg& operator = (const T&...
user2832531's user avatar
5 votes
1 answer
1k views

std::forward of rvalue ref to lambda?

Consider the following two snippets: Exhibit A: template<typename CalcFuncT> int perform_calc(CalcFuncT&& calcfunc) { precalc(); int const calc = calcfunc(); postcalc(); ...
Andrew Tomazos's user avatar
8 votes
2 answers
283 views

Deducing knowledge of original types, whilst simultaneously forwarding

Summary: I want to end up with a function that deduces the exact types it was called with and takes (e.g.) a tuple that forwards them (the types of which will be different from the exact types the ...
Flexo's user avatar
  • 88.3k
177 votes
3 answers
85k views

When to use std::forward to forward arguments?

C++0x shows an example of using std::forward: template<class T> void foo(T&& arg) { bar(std::forward<T>(arg)); } When is it advantageous to use std::forward, always? Also, it ...
coyotte508's user avatar
  • 9,595
0 votes
1 answer
266 views

Is this variadic template argument deduction correct?

I've been experimenting with variadic templates and argument forwarding. I think I've found some inconsistent behaviour. To illustrate, this program: #include <iostream> #include <typeinfo&...
spraff's user avatar
  • 32.9k
5 votes
3 answers
945 views

Perfect forwarding

If we have the following: template <class T> struct B{ T data; } struct A{ int data_array[100]; } int main() { A x; const A x_const; auto y1 = f(A()); auto y2 = f(x); auto y3 = ...
Clinton's user avatar
  • 22.9k
52 votes
2 answers
20k views

C++11 use-case for piecewise_construct of pair and tuple?

In N3059 I found the description of piecewise construction of pairs (and tuples) (and it is in the new Standard). But I can not see when I should use it. I found discussions about emplace and non-...
towi's user avatar
  • 22k

15 30 50 per page