简体   繁体   中英

How to define initializer list constructor without using std::initializer_list?

I want to make a small library of my own containers without relying on STL at all, as a form of exercise. How can I define an initializer list constructor for my classes without std::initializer_list? How is it even implemented?

How can I define an initializer list constructor for my classes without std::initializer_list ?

You don't. The very definition of "initializer list constructor" is tied into std::initializer_list . Just like the result of typeid is tied directly into std::type_info , and the result of sizeof and alignof is a std::size_t .

Attempting to use C++ while pretending the standard library in its entirety does not exist is folly. There are parts of it you can ignore without consequence, but if you want to have an "initializer list constructor", you have to use std::initializer_list .

The C++ standard library is not optional ; it is not divorced from C++ as a langauge. Parts of it are, but std::initializer_list isn't one of those parts.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM