Skip to content

Instantly share code, notes, and snippets.

@zhangyuchi
Last active August 29, 2015 14:09
Show Gist options
  • Save zhangyuchi/56531a460e686d263ad5 to your computer and use it in GitHub Desktop.
Save zhangyuchi/56531a460e686d263ad5 to your computer and use it in GitHub Desktop.
template usage
// return size of an array as a compile-time constant. (The
// array parameter has no name, because we care only about
// the number of elements it contains.)
template<typename T, std::size_t N> // see info
constexpr std::size_t arraySize(T (&)[N]) noexcept // below on
{ // constexpr
return N; // and
}
template<typename Container, typename Index> // final
decltype(auto) // C++14
authAndAccess(Container&& c, Index i) // version
{
authenticateUser();
return std::forward<Container>(c)[i];
}
std::deque<int> d;
authAndAccess(d, 5) = 10;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment