| 2210 | |
| 2211 | template<typename T, typename U> |
| 2212 | constexpr void assign(T & t, U && u) |
| 2213 | { |
| 2214 | using just_t = remove_cv_ref_t<T>; |
| 2215 | using just_u = remove_cv_ref_t<U>; |
| 2216 | if constexpr (is_move_assignable_v<just_u, just_t>) { |
| 2217 | static_assert( |
| 2218 | (!std::is_same_v<just_t, std::string> || |
| 2219 | !std::is_arithmetic_v<just_u>), |
| 2220 | "std::string is assignable from a char. Due to implicit " |
| 2221 | "conversions among arithmetic types, any arithmetic type " |
| 2222 | "(like int or double) is assignable to std::string. This " |
| 2223 | "is almost certainly not what you meant to write, so " |
| 2224 | "Boost.Parser disallows it. If you want to do this, write " |
| 2225 | "a semantic action and do it explicitly."); |
| 2226 | t = (U &&)u; |
| 2227 | } else if constexpr ( |
| 2228 | !is_tuple<just_t>::value && is_tuple<just_u>::value && |
| 2229 | std::is_aggregate_v<just_t> && |
| 2230 | !std::is_convertible_v<just_u &&, just_t> && |
| 2231 | is_struct_assignable_v<just_t, just_u>) { |
| 2232 | auto int_seq = |
| 2233 | std::make_integer_sequence<int, tuple_size_<just_u>>(); |
| 2234 | t = detail::tuple_to_aggregate<just_t>((U &&)u, int_seq); |
| 2235 | } else if constexpr ( |
| 2236 | is_tuple<just_t>::value && !is_tuple<just_u>::value && |
| 2237 | std::is_aggregate_v<just_u> && |
| 2238 | !std::is_convertible_v<just_u &&, just_t> && |
| 2239 | is_tuple_assignable_v<just_t, just_u>) { |
| 2240 | auto tie = detail::tie_aggregate(u); |
| 2241 | detail::aggregate_to_tuple( |
| 2242 | t, |
| 2243 | tie, |
| 2244 | std::make_integer_sequence<int, tuple_size_<just_t>>()); |
| 2245 | } else if constexpr (is_constructible_from_tuple_v< |
| 2246 | just_t, |
| 2247 | just_u>) { |
| 2248 | t = detail::make_from_tuple<just_t>((U &&)u); |
| 2249 | } else { |
| 2250 | static_assert( |
| 2251 | sizeof(T) && false, |
| 2252 | "Could not assign value, by: just assigning it; doing tuple " |
| 2253 | "-> aggregate or aggregate -> tuple conversions; or tuple " |
| 2254 | "-> class type construction."); |
| 2255 | } |
| 2256 | } |
| 2257 | |
| 2258 | template<typename T> |
| 2259 | constexpr void assign(T &, nope) |