/* * Copyright (c) 2014 Eran Pe'er. * * This program is made available under the terms of the MIT License. * * Created on Mar 10, 2014 */ #pragma once #include #include #include "mockutils/type_utils.hpp" namespace fakeit { struct DefaultValueInstatiationException { virtual ~DefaultValueInstatiationException() = default; virtual std::string what() const = 0; }; template struct is_constructible_type { static const bool value = std::is_default_constructible::type>::value && !std::is_abstract::type>::value; }; template struct DefaultValue; template struct DefaultValue::value>::type> { static C &value() { if (std::is_reference::value) { typename naked_type::type *ptr = nullptr; return *ptr; } class Exception : public DefaultValueInstatiationException { virtual std::string what() const override { return (std::string("Type ") + std::string(typeid(C).name()) + std::string( " is not default constructible. Could not instantiate a default return value")).c_str(); } }; throw Exception(); } }; template struct DefaultValue::value>::type> { static C &value() { static typename naked_type::type val{}; return val; } }; template<> struct DefaultValue { static void value() { return; } }; template<> struct DefaultValue { static bool &value() { static bool value{false}; return value; } }; template<> struct DefaultValue { static char &value() { static char value{0}; return value; } }; template<> struct DefaultValue { static char16_t &value() { static char16_t value{0}; return value; } }; template<> struct DefaultValue { static char32_t &value() { static char32_t value{0}; return value; } }; template<> struct DefaultValue { static wchar_t &value() { static wchar_t value{0}; return value; } }; template<> struct DefaultValue { static short &value() { static short value{0}; return value; } }; template<> struct DefaultValue { static int &value() { static int value{0}; return value; } }; template<> struct DefaultValue { static long &value() { static long value{0}; return value; } }; template<> struct DefaultValue { static long long &value() { static long long value{0}; return value; } }; template<> struct DefaultValue { static std::string &value() { static std::string value{}; return value; } }; }