Page 14 of 15

Modern & Effective C++ design ideas

Posted: May 29th, 2014, 6:11 am
by Cuchulainn
QuoteThis is going nowhere.I don't agree. We have 2 Visitor-based (slow/fast) solutions. Now the inproved C++ 11 version.

Modern & Effective C++ design ideas

Posted: May 29th, 2014, 9:57 pm
by Polter
outrun, looks pretty neat, `std::tuple` used for the purpose of passing types is a pretty cool idea :-)Now I'm wondering whether this can be generalized to arbitrary Callables?Not every Callable is convertible to a function pointer -- for instance, only captureless lambdas are.

Modern & Effective C++ design ideas

Posted: May 30th, 2014, 9:46 pm
by Polter
Looks promising!BTW, you can simplify the code a little using `std::true_type` / `std::false_type`:http://en.cppreference.com/w/cpp/types/ ... constantIn particular:template <typename T, typename _ = void> struct is_vector : std::false_type { };Come to think of it, `std::is_same` itself is already derived in this way:http://en.cppreference.com/w/cpp/types/is_samePerhaps you could write `is_vector` as an alias template?Consider:http://en.cppreference.com/w/cpp/language/type_alias// This compiles in isolation but doesn't seem to work just yet when plugged into your code in place of `is_vector`; did I miss something / intent?//// template <typename T> // using is_vector = typename std::is_same<T, std::vector<typename T::value_type, typename T::allocator_type>>;EDIT: readability improvement so far:// If we're targeting C++14 might as well use std::enable_if_t// `is_same_v` would've helped, too, but not sure if that's in: http://www.open-std.org/jtc1/sc22/wg21/ ... 3854.htm// At least, while still using `std::is_same`, we can replace `::value` with `{}()` -- this yields significant readability improvement in `invoke#1`// see N3545 "An Incremental Improvement to integral_constant" by Walter E. Brown// http://www.open-std.org/jtc1/sc22/wg21/ ... /n3545.pdf

Modern & Effective C++ design ideas

Posted: May 31st, 2014, 4:09 pm
by Cuchulainn
This Shape class will become obese/bloated in time (zillions of extra members functions). And the 'virtual' is not needed, as posted a while back. The Visitor subsumes rotate, mirror etc. etc. as instance 'drivers. I don't understand why you use virtual at all. remark; overloaded print() ==> console, gdi, Excel, AutoCAD, XML, Access.. all in Shape?