cpp_weekly icon indicating copy to clipboard operation
cpp_weekly copied to clipboard

Bridging C++ strong types and C-style functions

Open fsimonis opened this issue 2 years ago • 0 comments

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 and int 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++

fsimonis avatar Aug 04 '22 09:08 fsimonis