Freundlich's C++ toolkit
Coding style


When parameters are passed to functions, especially constructors, use one of the following cases to indicate ownership:


Following are various points on how to design the interface of a class:


Following are various points about functions:


Avoid explicit loops if possible. There are many cases in which an algorithm can be used instead. For example, instead of

int result{0};
for(int i{1}; i < n; ++i) result += i;

you can use fcppt::algorithm::fold

[](int i, int result) { return i + result; }

Algorithms can only be used with ranges, not with iterators. In case you need to encapsulate iterators, use fcppt::iterator::range. There are also special ranges like fcppt::int_range or fcppt::enum_::range. Some algorithms also accept a brigand::list as a range in case you need to iterate over types.


Initialize all objects and make them const if possible, especially do not use default constructors.

Provide functions for cases in which initialization can not be expressed directly. Consider a function that initializes an array of arbitrary size:

template<typename T, std::size_t N>
std::array<T,N> make_array();

Say you have a function T from_index(std::size_t) that creates an array element given an index. You can then initialize the array using

return fcppt::container::array::init<std::array<T,N>>(
[](std::size_t i) { return from_index<T>(i); });

In case you really need uninitialized objects, create a constructor that takes fcppt::no_init.