MCPcopy Create free account
hub / github.com/c42f/tinyformat / is_convertible

Class is_convertible

tinyformat.h:185–211  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

183// Test whether type T1 is convertible to type T2
184template <typename T1, typename T2>
185struct is_convertible
186{
187 private:
188 // two types of different size
189 struct fail { char dummy[2]; };
190 struct succeed { char dummy; };
191 // Try to convert a T1 to a T2 by plugging into tryConvert
192 static fail tryConvert(...);
193 static succeed tryConvert(const T2&);
194 static const T1& makeT1();
195 public:
196# ifdef _MSC_VER
197 // Disable spurious loss of precision warnings in tryConvert(makeT1())
198# pragma warning(push)
199# pragma warning(disable:4244)
200# pragma warning(disable:4267)
201# endif
202 // Standard trick: the (...) version of tryConvert will be chosen from
203 // the overload set only if the version taking a T2 doesn't match.
204 // Then we compare the sizes of the return types to check which
205 // function matched. Very neat, in a disgusting kind of way :)
206 static const bool value =
207 sizeof(tryConvert(makeT1())) == sizeof(succeed);
208# ifdef _MSC_VER
209# pragma warning(pop)
210# endif
211};
212
213
214// Detect when a type is not a wchar_t string

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected