Skip to main content
2 votes
1 answer
119 views

I'm working with a C++ class that includes both a conversion operator and a constructor that takes a std::initializer_list. According to Scott Meyers in "Effective Modern C++," Item 7, ...
sam's user avatar
  • 911
0 votes
0 answers
57 views

The following code when compiled with -fsanitize=address emits a stack-use-after-scope error in GCC 12.3 and Clang 20.1, but not GCC 14.2. #include <functional> #include <cstdint> #include ...
MarkB's user avatar
  • 2,230
0 votes
0 answers
63 views

I am designing a container (yeah, do not reinvent the wheel, I know). Let's call it Container<T>. I have a constructor to allow the initial number of elements: explicit Container(std::size_t ...
LeDYoM's user avatar
  • 999
2 votes
1 answer
160 views

#include <initializer_list> int main() { std::initializer_list<int> il = std::initializer_list<int>{1, 2, 3}; return 0; } As I understood it you should not copy std::...
Zitrax's user avatar
  • 20.7k
0 votes
2 answers
82 views

Some cpp class accept initializer_list as input, for example: std::map<std::string, int> m{{"CPU", 10}, {"GPU", 15}, {"RAM", 20}}; or std::map<std::string, int&...
athos's user avatar
  • 6,517
0 votes
2 answers
277 views

I have a Game class that stores the m_players as a data member (std::list<Player>) and each player has multiple data members, one of them being their m_name (std::string). When instantiating a ...
Rob Lauer's user avatar
0 votes
1 answer
118 views

My question is about the confusion in C++ default class member initialization between using an initializer list and calling a constructor. There is no ambiguity in the language but a possible ...
Thierry Lelegard's user avatar
3 votes
0 answers
402 views

I've got a class that basically contains a std::vector. I can default-construct an object of this class, leaving the contained std::vector empty. I can also value-construct it from a set of values, ...
Oersted's user avatar
  • 3,834
6 votes
1 answer
208 views

I can concisely (with braces) initialize 5 out of 6 of the following cases: of copyable of move-only array YES YES std::array YES YES std::vector YES NO The one case that doesn't seem to work is ...
Don Hatch's user avatar
  • 5,604
10 votes
1 answer
627 views

According to cppreference.com, std::initializer_lists have constexpr constructors and constexpr size methods (since C++14). Although the compiler I was using seemed to agree that the size of a ...
Adrian McCarthy's user avatar
1 vote
1 answer
224 views

C++ standard defines that initializer_list will be transformed in the following manner: struct X { X(std::initializer_list<double> v); }; X x{ 1,2,3 }; The initialization will be implemented ...
cbhattac's user avatar
  • 275
2 votes
2 answers
1k views

I wanted to figure this out, because I was running some unit tests and our system allows you to mark the test with one or more initializer lists, which will translate to multiple runs with different ...
Tomáš Zato's user avatar
0 votes
1 answer
119 views

It seems I don't understand braced init lists at all. Why does the following compile for operator=() (entity e) but not for the constructor (entity f)? Demo #include <cstdio> #include <...
glades's user avatar
  • 5,374
2 votes
3 answers
232 views

I have a hard time understanding how std::initializer_list works. I checked other questions, but found nothing relevant (or maybe I didn't see it?). Say I have this: template<typename T> struct ...
kebs's user avatar
  • 6,757
0 votes
1 answer
94 views

Code taken from the book Template Metaprogramming with C++, it doesn't compile i tried visual studio 22 i get the error: Error C2440 \<function-style-cast\>' : cannot convert from '...
ejy's user avatar
  • 1

15 30 50 per page
1
2 3 4 5