5 ms·
The iterator typing is much improved in C++11. It's just auto adt.begin().
by jevinskie 14y ago
The iterator typing is much improved in C++11. It's just auto adt.begin().
- btilly 14y agoThere is less verbose repeating of verbosity. But the types did not change in anything like the way that I would like. Try to translate http://perl.plover.com/Stream/stream.html http://perl.plover.com/Stream/stream.html into C++ iterators to see how the current abstraction limits the ways you can think about a program. By contrast suppose that my hypothetical iterator< foo > type was required to have a pointer overload, and supported the methods done() and next(). Now go back and try to translate that article - you'll find that it is pretty easy.
- X-Istence 14y agoInstead of me trying to understand Perl, tell me what problem you are trying to solve that having an hypothetical iterator<foo> would help solve.
- btilly 14y agoThe interface that I describe can be backed by a collection, data streamed externally (eg from a file), or by something generated on the fly. Therefore you can write code for all three cases that looks very similar. That article demonstrated the power of this idea by writing code that fairly efficiently generates the Hamming sequence, which consists of all positive integers whose only divisors are 2, 3, and 5. (So 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 16, 18, ...)
- X-Istence 14y agoYou can create your own type of iterator that when dereferenced spits out the next number/item, So long as your "end" iterator never matches your "current" iterator it will continue going on. Your "done" function is when "current" and "end" match. "next()" is "++current".
- reddit_clone 14y agoIndeed. First off, it is unrealistic to expect to rewrite perl/python scripts (much higher level scripting languages) in C++ and expect the same level of succinctness. C++ is for larger , high performance applications. The piper needs to be paid one way or another. If you rewrite a perl script in C++ for performance, the relative increase in verbosity is the price you pay.
- btilly 14y agoI accept that a price has to be paid for performance. However I believe that a substantial amount of verbosity could be removed without impacting said performance. In fact C++11 removes some with type deduction. I also get tired of typing some_big_type foo = some_big_type(); - is there a way to say, "I want this thing, and I want it to get the obvious default initialization?" Because what I type now is straight from the redundant department of redundancy department. (Yes, a typedef can make that shorter. You still write the idea twice.)
- copper 14y agoWhile I agree with most of what you say, that one seems wrong: assuming it exists, the default constructor will work when you type > some_big_type foo;
- mpyne 14y agoTry auto foo = some_big_type(); If you're not talking about initialization, but instead talking about construction, just do some_big_type foo; (no parens needed).
- btilly 14y agoIf you're not talking about initialization... I thought I was very clear when I said: "I want this thing, and I want it to get the obvious default initialization?" I often wound up typing something like this: std::vector< my_big_type > list_foo = std::vector< my_big_type >(); It seemed useless the first time, and just got sillier as time went on.
- 14y ago
- deleted 14y ago[deleted]