SL-20546: Rely on CTAD for 'narrow' class.
Now that we're building with C++17, we can use Class Template Argument Deduction to infer the type passed to the constructor of the 'narrow' class. We no longer require a narrow_holder class with a narrow() factory function.master
parent
96deda3f63
commit
7670f19082
|
|
@ -156,18 +156,15 @@ typedef int intptr_t;
|
|||
* type.
|
||||
*/
|
||||
// narrow_holder is a struct that accepts the passed value as its original
|
||||
// type and provides templated conversion functions to other types. Once we're
|
||||
// building with compilers that support Class Template Argument Deduction, we
|
||||
// can rename this class template 'narrow' and eliminate the narrow() factory
|
||||
// function below.
|
||||
// type and provides templated conversion functions to other types.
|
||||
template <typename FROM>
|
||||
class narrow_holder
|
||||
class narrow
|
||||
{
|
||||
private:
|
||||
FROM mValue;
|
||||
|
||||
public:
|
||||
narrow_holder(FROM value): mValue(value) {}
|
||||
narrow(FROM value): mValue(value) {}
|
||||
|
||||
/*---------------------- Narrowing unsigned to signed ----------------------*/
|
||||
template <typename TO,
|
||||
|
|
@ -207,13 +204,4 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
/// narrow() factory function returns a narrow_holder<FROM>(), which can be
|
||||
/// implicitly converted to the target type.
|
||||
template <typename FROM>
|
||||
inline
|
||||
narrow_holder<FROM> narrow(FROM value)
|
||||
{
|
||||
return { value };
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Reference in New Issue