template<class Container> Container::value_type first(Container&& c) { return *c.begin(); }
template<class ValueType> ValueType first(ValueType&& vt) { return vt; }
// Usage: first<int>(1); // 1
This call doesn't cause a compile error even though int::value_type does not exist--this is SFINAE. To make this work properly you'd also need to use compile-time introspection to disable the second function for types that have value_type, otherwise it's ambiguous.