initializer-list Questions

1

Solved

In the following code, struct A has two constructors: A(int) and A(std::initializer_list<char>). Then an object of the struct is created with A({0}): #include <initializer_list> struct...
Multipartite asked 3/2, 2022 at 7:25

2

Solved

I have some pretty complicated objects. They contain member variables of other objects. I understand the beauty of copy constructors cascading such that the default copy constructor can often work....
Yazzie asked 30/1, 2022 at 1:53

4

Imagine you have a simple matrix class template <typename T = double> class Matrix { T* data; size_t row, col; public: Matrix(size_t m, size_t n) : row(m), col(n), data(new T[m*n]) {} ...
Fazeli asked 4/4, 2013 at 11:44

4

I tried to compile the following snippets with gcc4.7 vector<pair<int,char> > vp = {{1,'a'},{2,'b'}}; //For pair vector, it works like a charm. vector<tuple<int,double,char> ...
Siler asked 15/9, 2012 at 10:28

2

Solved

#include <vector> int main() { auto v = std::vector{std::vector<int>{}}; return v.front().empty(); // error } See online demo However, according to Scott Meyers' Effective Modern C+...
Aida asked 30/8, 2021 at 7:18

3

Solved

I have a bunch of test vectors, presented in the form of hexadecimal strings: MSG: 6BC1BEE22E409F96E93D7E117393172A MAC: 070A16B46B4D4144F79BDD9DD04A287C MSG: 6BC1BEE22E409F96E93D7E117393172AAE2D8...
Harless asked 24/12, 2018 at 12:59

2

Solved

For some reasons I have to implement a multidimensional array class in C++. The array in question is something like this: template <typename T, typename = std::enable_if_t<std::is_arithmetic...
Unavailing asked 20/11, 2018 at 5:28

1

Solved

In the following C++20 program I put by mistake one extra pair of curved braces {} in B{{{{A{}}}}}: #include <iostream> struct A { A() { std::cout << "A() "; } A( A&&am...
Covington asked 18/7, 2021 at 9:32

2

Solved

Please consider this simplified c++14 program: #include <iostream> struct A { A() { std::cout << "A() "; } ~A() { std::cout << "~A() "; } }; int main() { ...
Patience asked 16/7, 2021 at 11:15

1

Solved

I compile this code below with GCC 11.1.0 with a flag -std=c++17. It occurs that on the stdout is printed initializer_list. I compiled the same code with MSVC with the flag -std=c++17 but it printe...
Startle asked 10/7, 2021 at 14:51

4

Solved

Why are the first two calls to doSomething OK by the compiler, but using two elements in the list causes an ambiguous call? #include <vector> #include <string> void doSomething(const ...
Accusative asked 6/1, 2017 at 14:15

4

Solved

Why does gcc throw a hissy fit if the initializer list order doesn't match variable order in the class? class myClass { public: int A; int B; myClass(); }; myClass::myClass() : B(1), A(2) {} ...
Rebeckarebeka asked 18/6, 2014 at 12:4

1

Solved

I have a question about C++ initializer list disambiguation which exhibits different behaviors between gcc, clang and Visual Studio. I wonder if this is "undefined behavior" (incorrect pr...
Gonium asked 25/2, 2021 at 16:24

5

Solved

I am trying to iterate over a number of std::lists, sorting each of them. This is the naive approach: #include<list> using namespace std; int main(void){ list<int> a,b,c; for(auto&am...
Renaterenato asked 30/7, 2015 at 13:14

3

Solved

I have been looking at how the initializer_list is implemented so I found section 18.9 of the standard and found a simple enough looking interface. I thought it would be instructive to make my own ...
Margit asked 10/8, 2013 at 17:7

2

Solved

Consider the following minimal example: #include <iostream> struct X { X() { std::cout << "Default-ctor" << std::endl; } X(std::initializer_list<int> l) { std...
Socle asked 15/12, 2020 at 1:31

4

Solved

In C++11, is it possible to do something similar to the following? template<typename T, size_t N> void foo(array<T, N> src) { ... } ... foo({1, 2, 3}) I'm currently running GCC 4.8...
Yocum asked 30/6, 2013 at 7:52

1

Solved

The following snippet compiles fine in vc++ and clang++, but fails on gcc (inc 9.2) unless i add an explicit cast. Which compiler is right here? #include <initializer_list> template<typ...

2

Solved

This is a follow-up of this question: Is it legal to declare a constexpr initializer_list object?. Since C++14, the std::initializer_list class has all of its methods marked with constexpr. It see...
Lanie asked 16/12, 2014 at 1:16

5

Solved

Why is std::initializer_list<_E>::size not allowable in a static_assert, even though it's declared as a constexpr in my libstdc++ (v. 4.6)? For example, the following code: template<class ...
Merchantman asked 25/3, 2011 at 22:12

3

Solved

I have a limited knowledge about c++. I tried to compile a c++ library and when I run the make file for the following header file mcmc_dhs.h #include <algorithm> #include <map> // intr...
Larynx asked 11/5, 2015 at 22:47

8

Solved

Am I allowed to move elements out of a std::initializer_list<T>? #include <initializer_list> #include <utility> template<typename T> void foo(std::initializer_list<T&gt...
Ramon asked 19/11, 2011 at 9:26

2

Simple question, does std::initializer_list heap allocate memory? I'm not talking about its element items, just the buffer itself to store the elements.
Esperance asked 15/5, 2020 at 17:57

1

Solved

I am trying to return the max value using the max function but its not working on 3 values. CodeBlocks Error: error: '__comp' cannot be used as a function The Code: #include <iost...
Nystrom asked 8/5, 2020 at 21:27

1

Solved

I am missing something with std::make_shared. Can't it resolve the type of a std::initializer_list, or am I doing something else wrong? #include <vector> #include <memory> class A {};...
Dentation asked 6/4, 2020 at 11:40

© 2022 - 2024 — McMap. All rights reserved.