Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v3] Concepts List #377

Open
silvanocerza opened this issue Mar 9, 2020 · 8 comments
Open

[v3] Concepts List #377

silvanocerza opened this issue Mar 9, 2020 · 8 comments

Comments

@silvanocerza
Copy link
Contributor

This is inspired by exercism/v3#167.

C++ reference

Concepts

The C++ concept exercises are based on concepts. The list below contains the concepts that have been identified for the C++ language.

Object-oriented

The core OO features a C++ developer should know about are:

Functional

C++ is a very flexible language, so lots of functional concepts apply to it:

Memory management

  • Object lifetime
  • RAII
  • Move-semantics
  • Free-store (heap)

Functions

  • Function overloading
  • Default parameters
  • Special member-functions
  • Operators

General

  • Arithmetic
  • Sameness (Equality)
  • Ordering
  • Conditionals
  • Enumeration (Container iteration)
  • Iterators
  • Namespaces
  • C-style Input/Output
  • Input/Output stream-based library
  • Templates
  • Metaprogramming
  • Exception handling
  • Implicit/explicit/contextual conversion
  • Destructuring (structured-bindings)
  • Concurrency (thread-safety)
  • Expressions vs statements
  • Value categories
  • Attributes
  • Slicing
  • String literals
  • Reflection (<type_traits>)
  • Undefined Behavior
  • Preprocessor
  • Concepts (Defer to C++2a)
  • Formatting (Defer to C++2a)

Types

Advanced topics

  • Pointers
  • Unions (union)

Concept interpretation

The concept exercises use the following concepts:

concept minimum standard version interpretation
numbers-basic C++98 Know of the existence of the two most basic number types, int and double, and understand that the former represents whole numbers, and the latter floating-point numbers. Know of basic operators such as multiplication and comparison. Know where it's documented, or at least how to search for it.
numbers-integral C++98 Know of the existence of the integer types: int, long, long long (with unsigned and fixed-width variants). Know when to use which type.
numbers-floating-point C++98 Know of the existence of the three floating point types: float, double and long double. Know when to use which type.
strings-basic C++98 Know of the existence of the std::string type. Know of some basic functions (like looking up a character at a position, or slicing the string). Know where it's documented, or at least how to search for it.
strings-formatting C++2a Know how to format a string. Know where it's documented, or at least how to search for it.
chrono-basic C++11 Know of the existence of the <chrono> header. Know of the existence of all three standard clocks and when to use them. Know how to access the current time. Know how to compare dates. Know how to convert a string to a chrono time point and vice versa. Know where it's documented, or at least how to search for it.
enums-basic C++98 Know of the existence of the enum class keyword. Know how to define enum members. Know how to use an enumerators. Know where it's documented, or at least how to search for it
enums-advanced C++98 Know how to define a "flags" enum class. Know how to add, remove or check for flags. Know the difference between a C-style enum and a strongly typed enum
casts-basic C++98 Know that it is sometimes possible to convert from one type to another type using static_cast.
conditionals C++98 Know of the existence of conditional execution statements (such as the if or switch statement).
conditional-injection C++17 Know of the existence of conditional code injection through if constexpr.
bitwise-operations C++98 Know how to apply bitwise operations to numbers. Know where it's documented, or at least how to search for it.
iteration-basic C++11 Know how to iterate over a collection (range-for).
arrays-basic C++11 Know of the existence of the std::array type. Know how to define an array. Know how to access elements in an array by index. Know how to iterate over elements in an array. Know of some basic functions (like finding the index of an element in an array). Know where it's documented, or at least how to search for it.
vectors-basic C++98 Know of the existence of the std::vector type. Know how to define an array. Know how to access elements in an vector by index. Know the unique properties of a vector. Know of some basic functions (like adding an element to a vector). Know where it's documented, or at least how to search for it.
maps-basic C++98 Know of the existence of the std::map and std::unordered_map types. Know how to define an map. Know how to access elements in an map by key. Know the unique properties of a map. Know of some basic functions (like adding an element to a map). Know where it's documented, or at least how to search for it.
sets-basic C++98 Know of the existence of the std::set and std::unordered_set types. Know how to define an set. Know how to access elements in a set. Know the unique properties of a set. Know of some basic functions (like adding an element to a set). Know where it's documented, or at least how to search for it.

This also indicates that for example strings-basic does not teach using custom formatting strings and that numbers-basic does not teach about integer undefined-behavior.

@silvanocerza
Copy link
Contributor Author

I think a central discussion where we, the maintainers, talk about the C++ Concepts is necessary, I've been inspired by the one created by @tehsphinx obviously, great idea. 😄

I hope this will promote contribution from everyone.

@AlexLeSang
Copy link
Contributor

Great idea to discuss this.
Please let me know what do you think about the following:

  • type_traints is not a reflection
  • Expand Templates to Function Templates and Class Templates
  • Add for Product types: struct and std::tuple
  • Add for Sum types: union and std::variant
  • Add String literals

@AeroStun
Copy link
Contributor

  • String literals: yes
  • Templates also cover template aliases and template variables
  • struct does not define a product type since you cannot sum two structs
  • type_traits contains all the current utilities for obtaining compile-time reflective information about things. It is pretty much the only use for it.
  • Sum types: yes, but we better classify union as an advanced topic, unlike std::variant

@AlexLeSang
Copy link
Contributor

To summarize:

  1. Add String literals to 'General'
  2. Add std::tuple to 'Types'
  3. Put 'Sum types std::variant' in 'Types',
  4. Add section of 'Advanced' topics and put union in it

@silvanocerza
Copy link
Contributor Author

type_traits is not exactly reflection has in other languages but it's the only way for C++ to obtain something similar, so I'd leave as it is.

We could leave Templates as a unique Concept and have multiple exercises for it, one for Function Templates, one for Class Templates etc.
Nothing stops us from doing that.

@AlexLeSang
Copy link
Contributor

type_traits is not exactly reflection has in other languages but it's the only way for C++ to obtain something similar, so I'd leave as it is.

For now that would suffice. I am not 100% on board with the name 'reflection' though. It clashes directly with what I would expect to find coming from Java or C#.

We could leave Templates as a unique Concept and have multiple exercises for it, one for Function Templates, one for Class Templates etc.
Nothing stops us from doing that.

I am all for that, Templates are extremely important concept and quite unique. I feel that there is a lot of misconceptions about template meta-programming so I believe that should be thoroughly explained in examples.

@silvanocerza
Copy link
Contributor Author

I've updated the issue with the updated Concepts from exercism/v3#887

@nicolechalmers nicolechalmers changed the title [C++] Concepts List [v3] Concepts List Jan 28, 2021
@nicolechalmers nicolechalmers transferred this issue from exercism/v3 Jan 28, 2021
@leap-heng
Copy link

Hello there, As I have seen that the C++ Functions is recommended from the Concepts list, however it has not yet been added to the repository, therefore can I give it a shot?

Here are the parts that I initially plan to include:

  • Function introduction
  • Function declaration
  • Function definition
  • Function call
  • void Functions
  • Function overloading
  • Function template
  • Default arguments

Feel free to add more suggestion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants