-
Notifications
You must be signed in to change notification settings - Fork 47
C Style
Currently we use C++17. However, due to poor portability, some new features are banned:
- filesystem
- execution
- optional
Every .cpp file should have a .h when something should be exposed to other compile unit.
Implementations with inline
and template
should be written into .hpp file.
We will remove headers as soon as C++20 modules become available.
We prefer static
than namespace {}
.
Smart pointers should be passed by value. void foo(std::shared_ptr<T>)
instead of .const std::shared_ptr<T> &
Never use out ref or ptr to store return data e.g. ,
just return object instead e.g. void VectorAdd(const Vector &a, const Vector &b, Vector &out)
Vector VectorAdd(const Vector &a, const Vector &b)
An exception is when return type should be inferred from template arguments.
Avoid using plain new
and delete
. Prefer using make_shared
and make_unique
.
We don't use exceptions right away. Prefer assert
more.
Every member-like function in template classes (including friend
and static
) should be decleared and defined (or implemented) inside the class definition. DO NOT place them outside.
Reduce usage of template member functions in template classes, if they are too awkward to call e.g. obj.template foo<T>()