Showing posts with label cpp_opqaue_type. Show all posts
Showing posts with label cpp_opqaue_type. Show all posts

Sep 21, 2016

[C++] Opaque Typedef library

video:
https://www.youtube.com/watch?v=jLdSjh8oqmE

library:
https://sourceforge.net/p/opaque-typedef/wiki/Home/#opaque-typedef-library

Reference:
Toward Opaque Typedefs for C++1Y, v2 (PDF)
[C++][NOTE][ORIGINAL] Strong typedef

Microprocessors have kinds of addresses:
  • Virtual address
  • Linear address
  • Guest physical address
  • Host physical address
  • DDR address



What kind of address am I talking about?

Opaque typedef

Idea:
  • Wrap a variable of some type in a new type
  • Mimic the interface of the original type, but using the new type

code:
struct linaddr : numeric_typedef<uint64_t, linaddr>
{
 using base = numeric_typedef<uint64_t, linaddr>;
 using base::base;
}


Merit:
  • Safer interfaces by removing implicit convertibility
  • Makes overloading on the new type possible
  • Turn semantic bugs into compile time errors

Aug 29, 2013

[C++][NOTE][ORIGINAL] Strong typedef

typedef does _not_ creates new type,

but sometimes, we really want _the_ same type but

with different _type_. Ok, it's a bit wordy.