Sep 25, 2018

[C++][CppCon 2018] Concepts is NOW.

Why even though current day job aren't anything about C++ but still coding side projects with it?

Because, it's about logic, math, fundamental computer science and speed. [advanced 'C', close to hardware, abstract with mathematical proofs]

Reference:


Type:
  • Specifies the set of operations that can be applied to an object  
    • implicitly and explicitly
    • relies on function declaration and language rules
  • Specifies how an object is laid out in memory
Concept:
  • Specifies the set of  operations that can be applied to an object.
    • implicitly and explicitly
    • relies on use patterns
  • Reflecting function declarations and language rules
  • Says nothing about the layout of the object


The fundamental is function overloading.
The fundamental of the fundamental is: name mangling :-)

Concepts:
Pros:
  • Better design
  • Readability, maintainability
  • Overloading
  • Fewer traits (duh~ brain teasing~)
 
Cons:
  •     I'll give it a try with examination.
 
Syntax Keywords:
requires (expression)

Concepts act as type for variable declaration:
Input_channel ch = foobar();

e.g
template<InputIterator Iter, typename Value>
    requires EqalityComparable<Value_type<Iter>, Value>
Iter find(Iter first, Iter last, Value val);

Golang doesn't support generic, thus we can see
in 'sort' package it uses 'interface' with member function
as contracts to sort data and Search takes a closure to capture
data structure that needs to be searched with a binary search.
Like python's bisect module, with strong type.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.