79274803

Date: 2024-12-12 10:55:14
Score: 0.5
Natty:
Report link

Thanks to @Jarod42 @LouisGo and @Oersted, I understood that the concept solution would be the best. My solution is

#include <vector>

template <typename T>
concept Container = requires(T t) {
    std::begin(t);
    std::end(t);
};

template <typename A, typename B>
B convert(A a)
{
   return B{a};
}

template <Container A, typename B>
B convert(A a)
{
   return B{a.front()};
}

template <typename A, Container B>
B convert(A a)
{
   return B{};
}

template <Container A, Container B>
B convert(A a)
{
   return B{};
}

template <typename T>
struct A
{
   T v_{};

   template <typename U>
   void assign(const A<U>& value)
   {
     v_ = convert<U, T>(value.v_);
   }
};

int main(int argc, const char *argv[])
{
   A<int> i;
   A<std::vector<int> > vi;

   vi.assign(i);

   return 0;
}
Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Whitelisted phrase (-1): solution is
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @Jarod42
  • User mentioned (0): @LouisGo
  • User mentioned (0): @Oersted
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: Nabuchodonozor