Pawel Por
unread,Dec 18, 2022, 5:13:22 AM12/18/22You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
Hello,
I'd like to understand the implementation of std::initializer_list constructor. I've copied the most recent std::lib implementation from git and building it with gcc 9.4.0 -std=c++2a. I get the following error:
error: no matching function for call to ‘custom_initializer<int>::custom_initializer(<brace-enclosed initializer list>)’
I don't understand what is the basic mechanism to pass the brace-enclosed list to the constructor.
Please give me some hints.
Thank you in advance
template<class _E>
class custom_initializer
{
public:
typedef _E value_type;
typedef const _E& reference;
typedef const _E& const_reference;
typedef size_t size_type;
typedef const _E* iterator;
typedef const _E* const_iterator;
private:
iterator _M_array;
size_type _M_len;
// The compiler can call a private constructor.
constexpr custom_initializer(const_iterator __a, size_type __l)
: _M_array(__a), _M_len(__l) { }
public:
constexpr custom_initializer() noexcept
: _M_array(0), _M_len(0) { }
// Number of elements.
constexpr size_type
size() const noexcept { return _M_len; }
// First element.
constexpr const_iterator
begin() const noexcept { return _M_array; }
// One past the last element.
constexpr const_iterator
end() const noexcept { return begin() + size(); }
};
int main(int argc, char **argv)
{
custom_initializer<int> ppp{1, 2, 3};
return 0;
}