Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does T& mean for some template argument T? [duplicate]

For example

template<class T>
struct Ref
{
    using type = T&;
};

Is Ref<T>::type the same as std::add_lvalue_reference<T>::type for all possible template arguments? E.g. int, int&, and int&&?

I just read the source code for std::add_lvalue_reference<T>. Quite sure they are equivalent.
If they are, we can save some space by simply writing T& instead.

like image 478
user1899020 Avatar asked Dec 08 '14 19:12

user1899020


People also ask

What does T minus 1 mean?

"T minus” (Pronounced: "tee minus") refers to the time remaining before something happens, especially on an official countdown clock. The “T” stands for time and negative numbers (minus) mean the time before the event happens, while positive numbers (plus) mean the time after it happens.

What T minus means?

T- (pronounced "T minus”) refers to the time remaining on the official countdown clock. The “T” stands for time. During planned holds in the countdown process (when the countdown clock is intentionally stopped), the T- time also stops. The L- time, however, is synced to the clock on the wall and continues to advance.

What is meant by t?

T is the twentieth letter of the English alphabet. 2. T or t is a written abbreviation for words beginning with 't', such as 'ton' and 'time'. 3.

What does the T mean in slang?

Tea is all about exchanging hot gossip. You can get tea, spill tea, and give tea. Often, the term is simply interchangeable with the letter “T." This slang term—like so many on this list—derives from '80s and '90s ball culture, which is where LGBTQ people performed in drag competitions to celebrate their queerness.


1 Answers

Table 53 in [meta.trans.ref] - definition of add_lvalue_reference:

If T names an object or function type then the member typedef type shall name T&; otherwise, if T names a type “rvalue reference to T1” then the member typedef type shall name T1&; otherwise, type shall name T.

Now recall the rules for reference collapsing:

If […] a type template-parameter (14.3.1) […] denotes a type TR that is a reference to a type T, an attempt to create the type “lvalue reference to cv TR” creates the type “lvalue reference to T […]

So the answer is yes:

  • For objects or functions the condition is trivially met. It's just T&, no reference collapsing involved.

  • For rvalue references, an lvalue reference to the type referred-to, T1, is created.

  • For lvalue references the exact reference type is preserved.

like image 161
Columbo Avatar answered Oct 05 '22 23:10

Columbo