SERVING THE QUANTITATIVE FINANCE COMMUNITY

 
User avatar
Cuchulainn
Posts: 59009
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Modern & Effective C++ design ideas

May 29th, 2014, 6:11 am

QuoteThis is going nowhere.I don't agree. We have 2 Visitor-based (slow/fast) solutions. Now the inproved C++ 11 version.
 
User avatar
Polter
Posts: 2526
Joined: April 29th, 2008, 4:55 pm

Modern & Effective C++ design ideas

May 29th, 2014, 9:57 pm

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.
 
User avatar
Polter
Posts: 2526
Joined: April 29th, 2008, 4:55 pm

Modern & Effective C++ design ideas

May 30th, 2014, 9:46 pm

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
Last edited by Polter on May 30th, 2014, 10:00 pm, edited 1 time in total.
 
User avatar
Cuchulainn
Posts: 59009
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Modern & Effective C++ design ideas

May 31st, 2014, 4:09 pm

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?
Last edited by Cuchulainn on May 30th, 2014, 10:00 pm, edited 1 time in total.
ABOUT WILMOTT

PW by JB

Wilmott.com has been "Serving the Quantitative Finance Community" since 2001. Continued...


Twitter LinkedIn Instagram

JOBS BOARD

JOBS BOARD

Looking for a quant job, risk, algo trading,...? Browse jobs here...


GZIP: On