Commit fd8ed198 authored by Kenton Varda's avatar Kenton Varda

Merge pull request #303 from katreniak/bka-styleGuide

style-guide: fix isConst and UnConst examples
parents 981814eb ff9d72e1
...@@ -323,16 +323,16 @@ In C++11, we can do better. Where before you would have declared a struct named ...@@ -323,16 +323,16 @@ In C++11, we can do better. Where before you would have declared a struct named
Example: Example:
template <typename T> struct IsConst_ { constexpr bool value = false; } template <typename T> struct IsConst_ { static constexpr bool value = false; };
template <typename T> struct IsConst_<const T> { constexpr bool value = true; } template <typename T> struct IsConst_<const T> { static constexpr bool value = true; };
template <typename T> constexpr bool isConst() { return IsConst_<T>::value; } template <typename T> constexpr bool isConst() { return IsConst_<T>::value; }
// Return true if T is const. // Return true if T is const.
Or: Or:
template <typename T> struct UnConst_ { typedef T Type; } template <typename T> struct UnConst_ { typedef T Type; };
template <typename T> struct UnConst_<T> { typedef T Type; } template <typename T> struct UnConst_<const T> { typedef T Type; };
template <typename T> using UnConst = UnConst_<T>::Type; template <typename T> using UnConst = typename UnConst_<T>::Type;
// If T is const, return the underlying non-const type. // If T is const, return the underlying non-const type.
// Otherwise, just return T. // Otherwise, just return T.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment