Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <xutility>
- #include <iostream>
- template <typename Ty>
- struct Simple_Array
- {
- Ty* data;
- const size_t size;
- Simple_Array(size_t size) :
- size(size),
- data(new Ty[size])
- {
- }
- // Throws an exception.
- template <class It>
- Simple_Array(It first, It last) :
- size(std::distance(first, last)),
- data(new Ty[size])
- {
- for (int i = 0; first != last; ++first, ++i)
- data[i] = *first;
- }
- // This version works without any problems.
- /* template <class It>
- Simple_Array(It first, It last) :
- Simple_Array(std::distance(first, last))
- {
- for (int i = 0; first != last; ++first, ++i)
- data[i] = *first;
- }*/
- };
- int main() {
- auto list = { 1, 2, 3, 4 };
- try {
- Simple_Array<int>(list.begin(), list.end());
- }
- catch (...) {
- std::cout << "Failed." << std::endl;
- }
- std::cin.get();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement