cpp_weekly
cpp_weekly copied to clipboard
Bridging C++ strong types and C-style functions
Channel
C++Weekly
Topics
C++ strong types are increasing in popularity, but some older code and existing libraries still use C-style interfaces of the underlying type. How do we bridge old and new code? How do we handle collections?
Old code or C-library interface:
int max( int a, int b );
int sum( int * values, int count );
Our goal are wrappers as such:
struct Integer { int i; };
// Simple entry exercise
Integer max ( Integer a, Integer b );
// Collection exercise (the meat of the topic)
// Use std::vector to simplify the example
Integer sum ( const std::vector<Integer> & values );
Topics
- C++ strong types
- Collections of strong types
- Converting arguments and results
- Converting between collections of strong and collections of underlying types. How to do this efficiently?
- Detecting and leveraging implementation-defined behaviour? Alignment rules, etc
- How does this change if we use a
class
andint get() const;
instead?
Length
Could be one long form or multiple incremental short episodes.
or a multi-hour talk, or a book, given this is about C++