Skip to main content
The 2024 Developer Survey results are live! See the results

Questions tagged [value-categories]

Value categories in C and C++ are a taxonomy of expressions. In C and in C++03, there are lvalues and rvalues. In C++11, there are lvalues, xvalues, and prvalues, as well as the mixed categories glvalues and rvalues.

value-categories
-1 votes
0 answers
15 views

What is meant by "pr values don't have identity", and why does function call returning an object by value not have identity? [duplicate]

The C++ Standard specifies that a pr-value is (among others) "a function call or an overloaded operator expression, whose return type is non-reference". Now I wonder why that exactly is the ...
Quantumwhisp's user avatar
3 votes
1 answer
59 views

What is the rationale for the expression class{}.refmem to be an lvalue expression

I came to know that S{}.rval is an lvalue expression. I want to know the rationale behind considering it an lvalue expression. Why are access to non-static member of reference type lvalue, even when ...
Oersted's user avatar
  • 1,706
-1 votes
1 answer
49 views

tool do determine the value category an expression: understanding the result when using references

Looking into definition of value-categories, I tried a snippet proposed here: https://stackoverflow.com/a/16638081/21691539 template <typename T> struct value_category { // Or can be an ...
Oersted's user avatar
  • 1,706
0 votes
0 answers
57 views

Why doesn't std::array<T,N>::operator[] return an rvalue reference for rvalue object? [duplicate]

std::array<T,N>::operator[] always returns an lvalue reference (const if needed), but what can possibly be the use of a line of code like this, which is valid C++? std::array<int,1>{1}[0] =...
Enlico's user avatar
  • 26.7k
1 vote
2 answers
124 views

Making a custom type behave like std::string

I have to define a few structs that contain a member of type std::string. I need to make them behave like std::string. In other words, they should be trivially convertible to std::string but not to ...
digito_evo's user avatar
  • 3,582
3 votes
0 answers
40 views

Why ranges::actions::join accepts lvalue ranges unless called with pipe syntax?

I use Range-v3 a lot, but mostly views and algorithms, not very much actions. As regards ranges::actions::join, why does the following happen? auto strs{std::vector{"one"s, "...
Enlico's user avatar
  • 26.7k
1 vote
3 answers
128 views

Value category of register in C++

I have come across the keyword register in C++ and I am curious about its value category. Are the variables created with the register keyword lvalue (because they can be referenced) or rvalue (because ...
M F's user avatar
  • 23
1 vote
1 answer
93 views

Is every xvalue an rvalue?

The standard denotes an xvalue as a glvalue whose resources can be reused. It also defines an rvalue as either an xvalue or a prvalue. And a prvalue is defined as an expression that either initializes ...
EL IAS's user avatar
  • 23
3 votes
1 answer
114 views

Is the rvalue passed to the function still rvalue or not?

I'm trying to understand everything I can about transfer semantics, rvalue, xvalue, prvalue, etc. I have the following function: void f(int&& x, int i) { std::cout << boost::...
MieszkoPasierbek's user avatar
2 votes
2 answers
128 views

How can I concatenate several vectors of unique pointers

The original use-case The usecase is that I have a function to retrieve some factories derived from FooFactory, std::vector<std::unique_ptr<FooFactory>> facts = getFactories(); and each ...
Enlico's user avatar
  • 26.7k
0 votes
0 answers
63 views

Why argument in std::move looks like (_Ty&& _Arg)? [duplicate]

Why argument in std::move looks like (_Ty&& _Arg)? Why we don't need to write overloads for (_Ty& _Arg) Why we don't get compilation error, when move l-value reference?
otstalyi's user avatar
  • 163
2 votes
1 answer
136 views

why different output when run program compiled with gcc and clang

I came across this example below when watching video about c++: #include <iostream> #include <type_traits> struct S { S() { std::cout << 'a'; } S(const S&) { std::cout &...
SICSU's user avatar
  • 61
0 votes
0 answers
87 views

static_cast to Universal Reference

I'm new to modern c++, and got messed up with value categories. There is discusssion about 'forward<T> vs static_cast<T&&>' Which says the purpose of using forward is to write clean code....
Nana's user avatar
  • 1
0 votes
2 answers
405 views

LARAVEL 9: Data from form modals not successfully saved to database when id_jenisizin value == 1 || id_jenisizin == 2

I'm creating an employee leave form, with 3 categories of permissions coming from another table, namely: "Terlambat", "Pulang Cepat ", "Sakit". select option for ...
akhiratunnisa's user avatar
1 vote
1 answer
380 views

Trying to understand: clang's side-effect warnings for typeid on a polymorphic object

This question is not about how to avoid the described warning. (Store in a reference beforehand; Or use dynamic_cast instead of typeid) I'm trying to understand why the warning exists in the first ...
Shmuel Valariola's user avatar

15 30 50 per page
1
2 3 4 5