Repository: mesos Updated Branches: refs/heads/master 1c97c0395 -> 8c7887abf
Fixed markdown rendering in C++ style guide. Review: https://reviews.apache.org/r/37123 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/8c7887ab Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/8c7887ab Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/8c7887ab Branch: refs/heads/master Commit: 8c7887abf50f050fd006e487a3fd49c9a73d0b87 Parents: 1c97c03 Author: Bernd Mathiske <[email protected]> Authored: Wed Aug 5 12:00:05 2015 +0200 Committer: Bernd Mathiske <[email protected]> Committed: Wed Aug 5 12:00:05 2015 +0200 ---------------------------------------------------------------------- docs/mesos-c++-style-guide.md | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/8c7887ab/docs/mesos-c++-style-guide.md ---------------------------------------------------------------------- diff --git a/docs/mesos-c++-style-guide.md b/docs/mesos-c++-style-guide.md index 9dca331..d8ad0ac 100644 --- a/docs/mesos-c++-style-guide.md +++ b/docs/mesos-c++-style-guide.md @@ -535,8 +535,9 @@ auto lambda = [ `constexpr` behaves as a combination of `inline` and `const` and hence must be defined before use in another `constexpr`. - Prefer `constexpr to `const` for all constant POD declarations, `constexpr` `char` arrays are preferred to `const` `string` literals. - ``` + Prefer `constexpr` to `const` for all constant POD declarations, `constexpr` `char` arrays are preferred to `const` `string` literals. + +~~~{.cpp} // OK constexpr char LITERAL[] = "value"; @@ -547,18 +548,20 @@ auto lambda = [ // Not OK - uncertain initialization order, cannot be used in other // constexpr statements. const string LITERAL("value"); +~~~ - ``` `constexpr` functions are evaluated at compile time if all their arguments are constant expressions. Otherwise they default to initialization at runtime. However `constexpr` functions are limited in that they cannot perform dynamic casts, memory allocation or calls to non-constexpr functions. Prefer `constexpr` over const inline functions. - ``` +~~~{.cpp} constexpr size_t MIN = 200; constexpr size_t MAX = 1000; constexpr size_t SPAN() { return MAX-MIN; } int array[SPAN()]; - ``` - Const expression constructors allow object initialization at compile time provided that all the constructor arguments are constexpr and the constuctor body is empty, i.e. all initialization is performed in the initialization list. Classes which provide constexpr constructors should normally also provide constexpr copy constructors to allow the class to be used in the return value from a constexpr function. - ``` +~~~ + +Const expression constructors allow object initialization at compile time provided that all the constructor arguments are `constexpr` and the constuctor body is empty, i.e. all initialization is performed in the initialization list. Classes which provide `constexpr` constructors should normally also provide `constexpr` copy constructors to allow the class to be used in the return value from a `constexpr` function. + +~~~{.cpp} class C { public: @@ -567,6 +570,6 @@ auto lambda = [ private: const int i; }; +~~~ - ``` - C++11 does not provide constexpr string or containers in the STL and hence constexpr cannot be used for any class using stout's Error() class. + C++11 does not provide `constexpr string` or `constexpr` containers in the STL and hence `constexpr` cannot be used for any class using stout's Error() class.
