Skip to main content
Stack Overflow
  1. About
  2. For Teams
Filter by
Sorted by
Tagged with
3 votes
3 answers
200 views

This question arouse from the question "why is const in function return type, which is a const pointer, ignored?" (const pointer, not pointer to const) int* const Foo(); is identical to int*...
5 votes
2 answers
318 views

In C++, a function with signature void f(A& a) (non-template) only binds to a lvalue. Is it possible for an rvalue to automatically cast itself to an lvalue? This is what I tried: #include <...
alfC's user avatar
  • 16.8k
4 votes
1 answer
117 views

Prior statement: I'm a programmer long coding in C++ and Python, so kindly pardon and teach if my question looks too silly due to my thinking of C in an OOD way. Also I've tried lot searching on ...
PkDrew's user avatar
  • 2,301
1 vote
1 answer
284 views

The code below appears to work just fine since the function returns by value: // return by value std::string getFoo() { const std::string& myStr = getBar(); return myStr; } std::string ...
user1643244's user avatar
-2 votes
1 answer
176 views

I have access to an API that returns const char *, where it is guaranteed that the underlying string is valid all through the program, like below: extern const char *getStr(); // an API that returns ...
2 votes
2 answers
141 views

In C++, the value category of an expression is determined by two independent properties: Whether the expression has an identity Whether the expression can be moved from (References: cppreference and ...
2 votes
1 answer
118 views

In the following code: #include <vector> int main() { using vec_t = std::vector<int>; vec_t v; auto it1{std::move(v).begin()};// type is vec_t::iterator auto it2{std::...
phinz's user avatar
  • 1,739
3 votes
1 answer
137 views

Given the following code that tries to allocate a lambda capture on the heap: #include <array> int test(void) { //auto big_lambda = new auto([d = std::array<int, 1024>{5,1,2}]() { ...
4 votes
1 answer
109 views

In C++, a named rvalue reference is lvalue. Why the below code yields "error: cannot bind non-const lvalue reference of type 'int&' to an rvalue of type 'int'"? int & unmove(int &...
zwhconst's user avatar
  • 1,657
1 vote
2 answers
158 views

I was reading C Notes for Professionals, in which, it claims that Compound Literals can only be lvalues. But LLMs have mixed answers upon that stating it could depend upon the context and could be ...
2 votes
1 answer
107 views

I was doing Leetcode when I stumbled upon this interesting technique. Here it is in short: #include <iostream> #include <vector> void print(std::vector<int>& vec) { for (int ...
Aik's user avatar
  • 65
1 vote
2 answers
115 views

I've got a function that returns a lambda. auto make_scanner(std::vector<int> const &v) { auto begin = v.cbegin(); auto end = v.cend(); return [begin, end] () mutable -> int { ...
1 vote
1 answer
147 views

In the minimum needed code snippet, in the move assignment, why is the commented line *arg = nullptr; illegal and arg.p = nullptr; okay? If I understand correctly, both are modifying rvalue, yet on ...
5 votes
1 answer
114 views

The following program was reduced to demonstrate the question. struct A has a constexpr member function that compares this against some pointer, which can be nullptr. Then this member function is ...
0 votes
0 answers
100 views

I want to pass a bunch of lambdas around without having to make copies. This is the declaration of one of the lambdas [ promise = std::move(promise), namedSeries = std::move(namedSeries) ] ...
John Glen's user avatar
  • 966

15 30 50 per page
1
2 3 4 5
...
50

AltStyle によって変換されたページ (->オリジナル) /