- 001
- 002
- 003
- 004
- 005
- 006
- 007
- 008
- 009
- 010
- 011
- 012
- 013
- 014
- 015
- 016
- 017
- 018
- 019
- 020
- 021
- 022
- 023
- 024
- 025
- 026
- 027
- 028
- 029
- 030
- 031
- 032
- 033
- 034
- 035
- 036
- 037
- 038
- 039
- 040
- 041
- 042
- 043
- 044
- 045
- 046
- 047
- 048
- 049
- 050
- 051
- 052
- 053
- 054
- 055
- 056
- 057
- 058
- 059
- 060
- 061
- 062
- 063
- 064
- 065
- 066
- 067
- 068
- 069
- 070
- 071
- 072
- 073
- 074
- 075
- 076
- 077
- 078
- 079
- 080
- 081
- 082
- 083
- 084
- 085
- 086
- 087
- 088
- 089
- 090
- 091
- 092
- 093
- 094
- 095
- 096
- 097
- 098
- 099
- 100
struct any
{
std::any _val;
inline constexpr any() : _val{}
{
}
inline constexpr any(undefined_t) noexcept : _val{}
{
}
inline constexpr any(std::nullopt_t) noexcept : _val{}
{
}
template <typename T>
inline constexpr any(const T &val) : _val{val}
{
}
inline any(const any &val) noexcept : _val{val._val}
{
}
inline any(any &&val) noexcept : _val{std::move(val._val)}
{
}
inline any &operator=(const any &val)
{
_val = val._val;
return *this;
}
inline operator bool()
{
if (!_val.has_value())
{
return false;
}
auto type_index = std::type_index(_val.type());
if (type_index == std::type_index(typeid(int)))
{
return std::any_cast<int>(_val) > 0;
}
else if (type_index == std::type_index(typeid(double)))
{
return std::any_cast<double>(_val) > 0;
}
else if (type_index == std::type_index(typeid(tstring)))
{
return std::any_cast<tstring>(_val).size() > 0;
}
else if (type_index == std::type_index(typeid(tstring_view)))
{
return std::any_cast<tstring_view>(_val).size() > 0;
}
else if (type_index == std::type_index(typeid(const char_t *)))
{
auto v = std::any_cast<const char_t *>(_val);
return !v;
}
else if (type_index == std::type_index(typeid(std::nullptr_t)))
{
return false;
}
else if (type_index == std::type_index(typeid(bool)))
{
return std::any_cast<bool>(_val);
}
return true;
}
template <typename N = void>
requires Arithmetic<N> any operator+(N n)
{
return any{std::any_cast<N>(this->_val) + n};
}
friend std::ostream &operator<<(std::ostream &os, const any &val_)
{
auto val = val_._val;
if (val.has_value())
{
auto type_index = std::type_index(val.type());
if (type_index == std::type_index(typeid(int)))
{
os << std::any_cast<int>(val);
}
else if (type_index == std::type_index(typeid(double)))
{
os << std::any_cast<double>(val);
}
else if (type_index == std::type_index(typeid(tstring)))
{
os << std::any_cast<tstring>(val);
}
bagrinho 22.05.2020 00:06 # +1
bormand 22.05.2020 00:11 # 0
var_dump($x);
bagrinho 22.05.2020 00:17 # 0
bormand 22.05.2020 00:26 # +5
PHP - простой и естественный язык для задачи, которую решает ОП. А крестобляди как всегда соснули.
bagrinho 23.05.2020 21:14 # 0
KOPOHABuPYC 27.05.2020 00:34 # 0