Last active
August 29, 2015 14:09
-
-
Save zhangyuchi/56531a460e686d263ad5 to your computer and use it in GitHub Desktop.
template usage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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