Skip to content

Instantly share code, notes, and snippets.

@Borgleader
Created February 7, 2016 14:23
Show Gist options
  • Save Borgleader/759e6b92ffb1d84ffaa9 to your computer and use it in GitHub Desktop.
Save Borgleader/759e6b92ffb1d84ffaa9 to your computer and use it in GitHub Desktop.
// No errors
template <typename Container>
std::size_t size_in_bytes(Container& c)
{
return c.size() * sizeof(typename Container::value_type);
}
//Error C2065 'value_type': undeclared identifier
//Error C2825 'Container': must be a class or namespace when followed by '::'
//Error C2510 'Container': left of '::' must be a class/struct/union
template <typename Container>
std::size_t size_in_bytes(Container&& c)
{
return c.size() * sizeof(typename Container::value_type); // <-- from this line (obv)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment