ThePhD / sol2

Sol3 (sol2 v3.0) - a C++ <-> Lua API wrapper with advanced features and top notch performance - is here, and it's great! Documentation:
http://sol2.rtfd.io/
MIT License
4.06k stars 493 forks source link

Cannot add user type derived from an STL container #1501

Open gentooise opened 1 year ago

gentooise commented 1 year ago

At first, I followed the example provided here to expose a container: https://github.com/ThePhD/sol2/issues/773#issuecomment-463550908 and it's working.

However, in my case I would like to have a container plus some additional add overloads, to simplify lua code.

This is my code so far:

struct MyObject
{
    int x;
    int y;
};

struct MyObjContainer : std::list<MyObject>
{
    // my own overloads
    void add(int x, int y) { push_back(MyObject{x, y}); } // should allow list:add(1, 2) instead of list:add(MyObject(1, 2))
    // void add(...) { ... } // many overloads, imagine MyObject with different arguments
};

and then:

lua.new_usertype<MyObject>("MyObject");
lua.new_usertype<MyObjContainer>(
    "Objects", sol::base_classes, sol::bases<std::list<MyObject>>(),
    "add", &MyObjContainer::add
);

But this just gives huge errors (I renamed real filenames):

In file included from /usr/include/c++/12.2.1/list:63,
                 from /myproj/mytest.h:8,
                 from /myproj/mytest.cpp:1:
/usr/include/c++/12.2.1/bits/stl_list.h: In instantiation of 'bool std::operator==(const __cxx11::list<_Tp, _Alloc>&, const __cxx11::list<_Tp, _Alloc>&) [with _Tp = MyObject; _Alloc = allocator<MyObject>]':
/usr/include/c++/12.2.1/bits/stl_function.h:502:34:   required from 'constexpr decltype ((forward<_Tp>(__t) == forward<_Up>(__u))) std::equal_to<void>::operator()(_Tp&&, _Up&&) const [with _Tp = MyObjContainer&; _Up = MyObjContainer&; decltype ((forward<_Tp>(__t) == forward<_Up>(__u))) = bool]'
/myproj/libs/sol/sol.hpp:12297:30:   required from 'int sol::detail::comparsion_operator_wrap(lua_State*) [with T = MyObjContainer; Op = std::equal_to<void>; lua_State = lua_State]'
/myproj/libs/sol/sol.hpp:23345:25:   required from 'void sol::detail::insert_default_registrations(IFx&&, Fx&&) [with T = MyObjContainer; IFx = sol::u_detail::register_usertype<MyObjContainer, sol::automagic_flags::all>(lua_State*, sol::automagic_enrollments)::<lambda(lua_State*, sol::u_detail::submetatable_type, sol::stateless_reference&)>::<lambda(sol::meta_function, lua_CFunction)>&; Fx = properties_enrollment_allowed&]'
/myproj/libs/sol/sol.hpp:24493:43:   required from 'int sol::u_detail::register_usertype(lua_State*, sol::automagic_enrollments) [with T = MyObjContainer; sol::automagic_flags enrollment_flags = sol::automagic_flags::all; lua_State = lua_State]'
/myproj/libs/sol/sol.hpp:26490:70:   required from 'sol::usertype<Class> sol::basic_table_core<<anonymous>, <template-parameter-1-2> >::new_usertype(Key&&, sol::constant_automagic_enrollments<enrollment_flags>) [with Class = MyObjContainer; Key = const char (&)[8]; sol::automagic_flags enrollment_flags = sol::automagic_flags::all; bool top_level = true; ref_t = sol::basic_reference<false>; sol::usertype<Class> = sol::basic_usertype<MyObjContainer, sol::basic_reference<false> >]'
/myproj/libs/sol/sol.hpp:26516:49:   required from 'sol::usertype<Class> sol::basic_table_core<<anonymous>, <template-parameter-1-2> >::new_usertype(Key&&, Arg&&, Args&& ...) [with Class = MyObjContainer; Key = const char (&)[8]; Arg = const sol::base_list<>&; Args = {sol::base_list<std::__cxx11::list<MyObject, std::allocator<MyObject> > >, const char (&)[4], void (MyObjContainer::*)(int, int)}; <template-parameter-2-5> = void; bool top_level = true; ref_t = sol::basic_reference<false>; sol::usertype<Class> = sol::basic_usertype<MyObjContainer, sol::basic_reference<false> >]'
/myproj/libs/sol/sol.hpp:27984:37:   required from 'sol::usertype<Class> sol::state_view::new_usertype(Args&& ...) [with Class = MyObjContainer; Args = {const char (&)[8], const sol::base_list<>&, sol::base_list<std::__cxx11::list<MyObject, std::allocator<MyObject> > >, const char (&)[4], void (MyObjContainer::*)(int, int)}; sol::usertype<Class> = sol::basic_usertype<MyObjContainer, sol::basic_reference<false> >]'
/myproj/mytest.cpp:21:37:   required from here
/usr/include/c++/12.2.1/bits/stl_list.h:2137:56: error: no match for 'operator==' (operand types are 'const MyObject' and 'const MyObject')
 2137 |       while (__i1 != __end1 && __i2 != __end2 && *__i1 == *__i2)
      |                                                  ~~~~~~^~~~~~~~
In file included from /usr/include/c++/12.2.1/bits/char_traits.h:39,
                 from /usr/include/c++/12.2.1/string:40,
                 from /myproj/mytest.h:3:
/usr/include/c++/12.2.1/bits/postypes.h:192:5: note: candidate: 'template<class _StateT> bool std::operator==(const fpos<_StateT>&, const fpos<_StateT>&)'
  192 |     operator==(const fpos<_StateT>& __lhs, const fpos<_StateT>& __rhs)
      |     ^~~~~~~~
/usr/include/c++/12.2.1/bits/postypes.h:192:5: note:   template argument deduction/substitution failed:
/usr/include/c++/12.2.1/bits/stl_list.h:2137:56: note:   'const MyObject' is not derived from 'const std::fpos<_StateT>'
 2137 |       while (__i1 != __end1 && __i2 != __end2 && *__i1 == *__i2)
      |                                                  ~~~~~~^~~~~~~~
In file included from /usr/include/c++/12.2.1/string:41:
/usr/include/c++/12.2.1/bits/allocator.h:219:5: note: candidate: 'template<class _T1, class _T2> bool std::operator==(const allocator<_CharT>&, const allocator<_T2>&)'
  219 |     operator==(const allocator<_T1>&, const allocator<_T2>&)
      |     ^~~~~~~~
/usr/include/c++/12.2.1/bits/allocator.h:219:5: note:   template argument deduction/substitution failed:
/usr/include/c++/12.2.1/bits/stl_list.h:2137:56: note:   'const MyObject' is not derived from 'const std::allocator<_CharT>'
 2137 |       while (__i1 != __end1 && __i2 != __end2 && *__i1 == *__i2)
      |                                                  ~~~~~~^~~~~~~~
In file included from /usr/include/c++/12.2.1/string:47:
/usr/include/c++/12.2.1/bits/stl_iterator.h:444:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator==(const reverse_iterator<_Iterator>&, const reverse_iterator<_Iterator>&)'
  444 |     operator==(const reverse_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/12.2.1/bits/stl_iterator.h:444:5: note:   template argument deduction/substitution failed:
/usr/include/c++/12.2.1/bits/stl_list.h:2137:56: note:   'const MyObject' is not derived from 'const std::reverse_iterator<_Iterator>'
 2137 |       while (__i1 != __end1 && __i2 != __end2 && *__i1 == *__i2)
      |                                                  ~~~~~~^~~~~~~~
/usr/include/c++/12.2.1/bits/stl_iterator.h:489:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator==(const reverse_iterator<_Iterator>&, const reverse_iterator<_IteratorR>&)'
  489 |     operator==(const reverse_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/12.2.1/bits/stl_iterator.h:489:5: note:   template argument deduction/substitution failed:
/usr/include/c++/12.2.1/bits/stl_list.h:2137:56: note:   'const MyObject' is not derived from 'const std::reverse_iterator<_Iterator>'
 2137 |       while (__i1 != __end1 && __i2 != __end2 && *__i1 == *__i2)
      |                                                  ~~~~~~^~~~~~~~
/usr/include/c++/12.2.1/bits/stl_iterator.h:1656:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator==(const move_iterator<_IteratorL>&, const move_iterator<_IteratorR>&)'
 1656 |     operator==(const move_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/12.2.1/bits/stl_iterator.h:1656:5: note:   template argument deduction/substitution failed:
/usr/include/c++/12.2.1/bits/stl_list.h:2137:56: note:   'const MyObject' is not derived from 'const std::move_iterator<_IteratorL>'
 2137 |       while (__i1 != __end1 && __i2 != __end2 && *__i1 == *__i2)
      |                                                  ~~~~~~^~~~~~~~
/usr/include/c++/12.2.1/bits/stl_iterator.h:1726:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator==(const move_iterator<_IteratorL>&, const move_iterator<_IteratorL>&)'
 1726 |     operator==(const move_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/12.2.1/bits/stl_iterator.h:1726:5: note:   template argument deduction/substitution failed:
/usr/include/c++/12.2.1/bits/stl_list.h:2137:56: note:   'const MyObject' is not derived from 'const std::move_iterator<_IteratorL>'
 2137 |       while (__i1 != __end1 && __i2 != __end2 && *__i1 == *__i2)
      |                                                  ~~~~~~^~~~~~~~
In file included from /usr/include/c++/12.2.1/bits/stl_algobase.h:64,
                 from /usr/include/c++/12.2.1/string:50:
/usr/include/c++/12.2.1/bits/stl_pair.h:640:5: note: candidate: 'template<class _T1, class _T2> constexpr bool std::operator==(const pair<_T1, _T2>&, const pair<_T1, _T2>&)'
  640 |     operator==(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
      |     ^~~~~~~~
/usr/include/c++/12.2.1/bits/stl_pair.h:640:5: note:   template argument deduction/substitution failed:
/usr/include/c++/12.2.1/bits/stl_list.h:2137:56: note:   'const MyObject' is not derived from 'const std::pair<_T1, _T2>'
 2137 |       while (__i1 != __end1 && __i2 != __end2 && *__i1 == *__i2)
      |                                                  ~~~~~~^~~~~~~~
In file included from /usr/include/c++/12.2.1/bits/basic_string.h:47,
                 from /usr/include/c++/12.2.1/string:53:
/usr/include/c++/12.2.1/string_view:540:5: note: candidate: 'template<class _CharT, class _Traits> constexpr bool std::operator==(basic_string_view<_CharT, _Traits>, basic_string_view<_CharT, _Traits>)'
  540 |     operator==(basic_string_view<_CharT, _Traits> __x,
      |     ^~~~~~~~
/usr/include/c++/12.2.1/string_view:540:5: note:   template argument deduction/substitution failed:
/usr/include/c++/12.2.1/bits/stl_list.h:2137:56: note:   'MyObject' is not derived from 'std::basic_string_view<_CharT, _Traits>'
 2137 |       while (__i1 != __end1 && __i2 != __end2 && *__i1 == *__i2)
      |                                                  ~~~~~~^~~~~~~~
/usr/include/c++/12.2.1/string_view:546:5: note: candidate: 'template<class _CharT, class _Traits> constexpr bool std::operator==(basic_string_view<_CharT, _Traits>, __type_identity_t<basic_string_view<_CharT, _Traits> >)'
  546 |     operator==(basic_string_view<_CharT, _Traits> __x,
      |     ^~~~~~~~
/usr/include/c++/12.2.1/string_view:546:5: note:   template argument deduction/substitution failed:
/usr/include/c++/12.2.1/bits/stl_list.h:2137:56: note:   'MyObject' is not derived from 'std::basic_string_view<_CharT, _Traits>'
 2137 |       while (__i1 != __end1 && __i2 != __end2 && *__i1 == *__i2)
      |                                                  ~~~~~~^~~~~~~~
/usr/include/c++/12.2.1/string_view:569:5: note: candidate: 'template<class _CharT, class _Traits> constexpr bool std::operator==(__type_identity_t<basic_string_view<_CharT, _Traits> >, basic_string_view<_CharT, _Traits>)'
  569 |     operator==(__type_identity_t<basic_string_view<_CharT, _Traits>> __x,
      |     ^~~~~~~~
/usr/include/c++/12.2.1/string_view:569:5: note:   template argument deduction/substitution failed:
/usr/include/c++/12.2.1/bits/stl_list.h:2137:56: note:   'MyObject' is not derived from 'std::basic_string_view<_CharT, _Traits>'
 2137 |       while (__i1 != __end1 && __i2 != __end2 && *__i1 == *__i2)
      |                                                  ~~~~~~^~~~~~~~
/usr/include/c++/12.2.1/bits/basic_string.h:3575:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> bool std::operator==(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 3575 |     operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/12.2.1/bits/basic_string.h:3575:5: note:   template argument deduction/substitution failed:
/usr/include/c++/12.2.1/bits/stl_list.h:2137:56: note:   'const MyObject' is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
 2137 |       while (__i1 != __end1 && __i2 != __end2 && *__i1 == *__i2)
      |                                                  ~~~~~~^~~~~~~~
/usr/include/c++/12.2.1/bits/basic_string.h:3584:5: note: candidate: 'template<class _CharT> typename __gnu_cxx::__enable_if<std::__is_char<_Tp>::__value, bool>::__type std::operator==(const __cxx11::basic_string<_CharT>&, const __cxx11::basic_string<_CharT>&)'
 3584 |     operator==(const basic_string<_CharT>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/12.2.1/bits/basic_string.h:3584:5: note:   template argument deduction/substitution failed:
/usr/include/c++/12.2.1/bits/stl_list.h:2137:56: note:   'const MyObject' is not derived from 'const std::__cxx11::basic_string<_CharT>'
 2137 |       while (__i1 != __end1 && __i2 != __end2 && *__i1 == *__i2)
      |                                                  ~~~~~~^~~~~~~~
/usr/include/c++/12.2.1/bits/basic_string.h:3599:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> bool std::operator==(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, const _CharT*)'
 3599 |     operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/12.2.1/bits/basic_string.h:3599:5: note:   template argument deduction/substitution failed:
/usr/include/c++/12.2.1/bits/stl_list.h:2137:56: note:   'const MyObject' is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
 2137 |       while (__i1 != __end1 && __i2 != __end2 && *__i1 == *__i2)
      |                                                  ~~~~~~^~~~~~~~
/usr/include/c++/12.2.1/bits/basic_string.h:3640:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> bool std::operator==(const _CharT*, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 3640 |     operator==(const _CharT* __lhs,
      |     ^~~~~~~~
/usr/include/c++/12.2.1/bits/basic_string.h:3640:5: note:   template argument deduction/substitution failed:
/usr/include/c++/12.2.1/bits/stl_list.h:2137:56: note:   mismatched types 'const _CharT*' and 'MyObject'
 2137 |       while (__i1 != __end1 && __i2 != __end2 && *__i1 == *__i2)
      |                                                  ~~~~~~^~~~~~~~
In file included from /myproj/other.h:4:
/usr/include/c++/12.2.1/tuple:1496:5: note: candidate: 'template<class ... _TElements, class ... _UElements> constexpr bool std::operator==(const tuple<_UTypes ...>&, const tuple<_UTypes ...>&)'
 1496 |     operator==(const tuple<_TElements...>& __t,
      |     ^~~~~~~~
/usr/include/c++/12.2.1/tuple:1496:5: note:   template argument deduction/substitution failed:
/usr/include/c++/12.2.1/bits/stl_list.h:2137:56: note:   'const MyObject' is not derived from 'const std::tuple<_UTypes ...>'
 2137 |       while (__i1 != __end1 && __i2 != __end2 && *__i1 == *__i2)
      |                                                  ~~~~~~^~~~~~~~
In file included from /usr/include/c++/12.2.1/unordered_map:47,
                 from /myproj/other.h:5:
/usr/include/c++/12.2.1/bits/unordered_map.h:2134:5: note: candidate: 'template<class _Key1, class _Tp1, class _Hash1, class _Pred1, class _Alloc1> bool std::operator==(const unordered_map<_Key1, _Tp1, _Hash1, _Pred1, _Alloc1>&, const unordered_map<_Key1, _Tp1, _Hash1, _Pred1, _Alloc1>&)'
 2134 |     operator==(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
      |     ^~~~~~~~
/usr/include/c++/12.2.1/bits/unordered_map.h:2134:5: note:   template argument deduction/substitution failed:
/usr/include/c++/12.2.1/bits/stl_list.h:2137:56: note:   'const MyObject' is not derived from 'const std::unordered_map<_Key1, _Tp1, _Hash1, _Pred1, _Alloc1>'
 2137 |       while (__i1 != __end1 && __i2 != __end2 && *__i1 == *__i2)
      |                                                  ~~~~~~^~~~~~~~
/usr/include/c++/12.2.1/bits/unordered_map.h:2148:5: note: candidate: 'template<class _Key1, class _Tp1, class _Hash1, class _Pred1, class _Alloc1> bool std::operator==(const unordered_multimap<_Key1, _Tp1, _Hash1, _Pred1, _Alloc1>&, const unordered_multimap<_Key1, _Tp1, _Hash1, _Pred1, _Alloc1>&)'
 2148 |     operator==(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
      |     ^~~~~~~~
/usr/include/c++/12.2.1/bits/unordered_map.h:2148:5: note:   template argument deduction/substitution failed:
/usr/include/c++/12.2.1/bits/stl_list.h:2137:56: note:   'const MyObject' is not derived from 'const std::unordered_multimap<_Key1, _Tp1, _Hash1, _Pred1, _Alloc1>'
 2137 |       while (__i1 != __end1 && __i2 != __end2 && *__i1 == *__i2)
      |                                                  ~~~~~~^~~~~~~~
In file included from /usr/include/c++/12.2.1/unordered_set:47,
                 from /myproj/other.h:6:
/usr/include/c++/12.2.1/bits/unordered_set.h:1804:5: note: candidate: 'template<class _Value1, class _Hash1, class _Pred1, class _Alloc1> bool std::operator==(const unordered_set<_Value1, _Hash1, _Pred1, _Alloc1>&, const unordered_set<_Value1, _Hash1, _Pred1, _Alloc1>&)'
 1804 |     operator==(const unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
      |     ^~~~~~~~
/usr/include/c++/12.2.1/bits/unordered_set.h:1804:5: note:   template argument deduction/substitution failed:
/usr/include/c++/12.2.1/bits/stl_list.h:2137:56: note:   'const MyObject' is not derived from 'const std::unordered_set<_Value1, _Hash1, _Pred1, _Alloc1>'
 2137 |       while (__i1 != __end1 && __i2 != __end2 && *__i1 == *__i2)
      |                                                  ~~~~~~^~~~~~~~
/usr/include/c++/12.2.1/bits/unordered_set.h:1818:5: note: candidate: 'template<class _Value1, class _Hash1, class _Pred1, class _Alloc1> bool std::operator==(const unordered_multiset<_Value1, _Hash1, _Pred1, _Alloc1>&, const unordered_multiset<_Value1, _Hash1, _Pred1, _Alloc1>&)'
 1818 |     operator==(const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
      |     ^~~~~~~~
/usr/include/c++/12.2.1/bits/unordered_set.h:1818:5: note:   template argument deduction/substitution failed:
/usr/include/c++/12.2.1/bits/stl_list.h:2137:56: note:   'const MyObject' is not derived from 'const std::unordered_multiset<_Value1, _Hash1, _Pred1, _Alloc1>'
 2137 |       while (__i1 != __end1 && __i2 != __end2 && *__i1 == *__i2)
      |                                                  ~~~~~~^~~~~~~~
In file included from /usr/include/c++/12.2.1/bits/locale_facets.h:48,
                 from /usr/include/c++/12.2.1/bits/basic_ios.h:37,
                 from /usr/include/c++/12.2.1/ios:44,
                 from /usr/include/c++/12.2.1/istream:38,
                 from /usr/include/c++/12.2.1/fstream:38,
                 from /myproj/other2.h:5,
                 from /myproj/other.h:9:
/usr/include/c++/12.2.1/bits/streambuf_iterator.h:233:5: note: candidate: 'template<class _CharT, class _Traits> bool std::operator==(const istreambuf_iterator<_CharT, _Traits>&, const istreambuf_iterator<_CharT, _Traits>&)'
  233 |     operator==(const istreambuf_iterator<_CharT, _Traits>& __a,
      |     ^~~~~~~~
/usr/include/c++/12.2.1/bits/streambuf_iterator.h:233:5: note:   template argument deduction/substitution failed:
/usr/include/c++/12.2.1/bits/stl_list.h:2137:56: note:   'const MyObject' is not derived from 'const std::istreambuf_iterator<_CharT, _Traits>'
 2137 |       while (__i1 != __end1 && __i2 != __end2 && *__i1 == *__i2)
      |                                                  ~~~~~~^~~~~~~~
In file included from /usr/include/c++/12.2.1/functional:59,
                 from /myproj/other2.h:6:
/usr/include/c++/12.2.1/bits/std_function.h:718:5: note: candidate: 'template<class _Res, class ... _Args> bool std::operator==(const function<_Res(_ArgTypes ...)>&, nullptr_t)'
  718 |     operator==(const function<_Res(_Args...)>& __f, nullptr_t) noexcept
      |     ^~~~~~~~
/usr/include/c++/12.2.1/bits/std_function.h:718:5: note:   template argument deduction/substitution failed:
/usr/include/c++/12.2.1/bits/stl_list.h:2137:56: note:   'const MyObject' is not derived from 'const std::function<_Res(_ArgTypes ...)>'
 2137 |       while (__i1 != __end1 && __i2 != __end2 && *__i1 == *__i2)
      |                                                  ~~~~~~^~~~~~~~
/usr/include/c++/12.2.1/bits/std_function.h:725:5: note: candidate: 'template<class _Res, class ... _Args> bool std::operator==(nullptr_t, const function<_Res(_ArgTypes ...)>&)'
  725 |     operator==(nullptr_t, const function<_Res(_Args...)>& __f) noexcept
      |     ^~~~~~~~
/usr/include/c++/12.2.1/bits/std_function.h:725:5: note:   template argument deduction/substitution failed:
/usr/include/c++/12.2.1/bits/stl_list.h:2137:56: note:   'const MyObject' is not derived from 'const std::function<_Res(_ArgTypes ...)>'
 2137 |       while (__i1 != __end1 && __i2 != __end2 && *__i1 == *__i2)
      |                                                  ~~~~~~^~~~~~~~
In file included from /usr/include/c++/12.2.1/vector:64,
                 from /usr/include/c++/12.2.1/functional:62:
/usr/include/c++/12.2.1/bits/stl_vector.h:2035:5: note: candidate: 'template<class _Tp, class _Alloc> bool std::operator==(const vector<_Tp, _Alloc>&, const vector<_Tp, _Alloc>&)'
 2035 |     operator==(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y)
      |     ^~~~~~~~
/usr/include/c++/12.2.1/bits/stl_vector.h:2035:5: note:   template argument deduction/substitution failed:
/usr/include/c++/12.2.1/bits/stl_list.h:2137:56: note:   'const MyObject' is not derived from 'const std::vector<_Tp, _Alloc>'
 2137 |       while (__i1 != __end1 && __i2 != __end2 && *__i1 == *__i2)
      |                                                  ~~~~~~^~~~~~~~
In file included from /usr/include/c++/12.2.1/functional:63:
/usr/include/c++/12.2.1/array:304:5: note: candidate: 'template<class _Tp, long unsigned int _Nm> bool std::operator==(const array<_Tp, _Nm>&, const array<_Tp, _Nm>&)'
  304 |     operator==(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
      |     ^~~~~~~~
/usr/include/c++/12.2.1/array:304:5: note:   template argument deduction/substitution failed:
/usr/include/c++/12.2.1/bits/stl_list.h:2137:56: note:   'const MyObject' is not derived from 'const std::array<_Tp, _Nm>'
 2137 |       while (__i1 != __end1 && __i2 != __end2 && *__i1 == *__i2)
      |                                                  ~~~~~~^~~~~~~~
In file included from /usr/include/c++/12.2.1/memory:76,
                 from /myproj/other2.h:10:
/usr/include/c++/12.2.1/bits/unique_ptr.h:824:5: note: candidate: 'template<class _Tp, class _Dp, class _Up, class _Ep> bool std::operator==(const unique_ptr<_Tp, _Dp>&, const unique_ptr<_Up, _Ep>&)'
  824 |     operator==(const unique_ptr<_Tp, _Dp>& __x,
      |     ^~~~~~~~
/usr/include/c++/12.2.1/bits/unique_ptr.h:824:5: note:   template argument deduction/substitution failed:
/usr/include/c++/12.2.1/bits/stl_list.h:2137:56: note:   'const MyObject' is not derived from 'const std::unique_ptr<_Tp, _Dp>'
 2137 |       while (__i1 != __end1 && __i2 != __end2 && *__i1 == *__i2)
      |                                                  ~~~~~~^~~~~~~~
/usr/include/c++/12.2.1/bits/unique_ptr.h:832:5: note: candidate: 'template<class _Tp, class _Dp> bool std::operator==(const unique_ptr<_Tp, _Dp>&, nullptr_t)'
  832 |     operator==(const unique_ptr<_Tp, _Dp>& __x, nullptr_t) noexcept
      |     ^~~~~~~~
/usr/include/c++/12.2.1/bits/unique_ptr.h:832:5: note:   template argument deduction/substitution failed:
/usr/include/c++/12.2.1/bits/stl_list.h:2137:56: note:   'const MyObject' is not derived from 'const std::unique_ptr<_Tp, _Dp>'
 2137 |       while (__i1 != __end1 && __i2 != __end2 && *__i1 == *__i2)
      |                                                  ~~~~~~^~~~~~~~
/usr/include/c++/12.2.1/bits/unique_ptr.h:840:5: note: candidate: 'template<class _Tp, class _Dp> bool std::operator==(nullptr_t, const unique_ptr<_Tp, _Dp>&)'
  840 |     operator==(nullptr_t, const unique_ptr<_Tp, _Dp>& __x) noexcept
      |     ^~~~~~~~
/usr/include/c++/12.2.1/bits/unique_ptr.h:840:5: note:   template argument deduction/substitution failed:
/usr/include/c++/12.2.1/bits/stl_list.h:2137:56: note:   'const MyObject' is not derived from 'const std::unique_ptr<_Tp, _Dp>'
 2137 |       while (__i1 != __end1 && __i2 != __end2 && *__i1 == *__i2)
      |                                                  ~~~~~~^~~~~~~~
In file included from /usr/include/c++/12.2.1/bits/shared_ptr.h:53,
                 from /usr/include/c++/12.2.1/memory:77:
/usr/include/c++/12.2.1/bits/shared_ptr_base.h:1793:5: note: candidate: 'template<class _Tp1, class _Tp2, __gnu_cxx::_Lock_policy _Lp> bool std::operator==(const __shared_ptr<_Tp1, _Lp>&, const __shared_ptr<_Tp2, _Lp>&)'
 1793 |     operator==(const __shared_ptr<_Tp1, _Lp>& __a,
      |     ^~~~~~~~
/usr/include/c++/12.2.1/bits/shared_ptr_base.h:1793:5: note:   template argument deduction/substitution failed:
/usr/include/c++/12.2.1/bits/stl_list.h:2137:56: note:   'const MyObject' is not derived from 'const std::__shared_ptr<_Tp1, _Lp>'
 2137 |       while (__i1 != __end1 && __i2 != __end2 && *__i1 == *__i2)
      |                                                  ~~~~~~^~~~~~~~
/usr/include/c++/12.2.1/bits/shared_ptr_base.h:1799:5: note: candidate: 'template<class _Tp, __gnu_cxx::_Lock_policy _Lp> bool std::operator==(const __shared_ptr<_Tp, _Lp>&, nullptr_t)'
 1799 |     operator==(const __shared_ptr<_Tp, _Lp>& __a, nullptr_t) noexcept
      |     ^~~~~~~~
/usr/include/c++/12.2.1/bits/shared_ptr_base.h:1799:5: note:   template argument deduction/substitution failed:
/usr/include/c++/12.2.1/bits/stl_list.h:2137:56: note:   'const MyObject' is not derived from 'const std::__shared_ptr<_Tp, _Lp>'
 2137 |       while (__i1 != __end1 && __i2 != __end2 && *__i1 == *__i2)
      |                                                  ~~~~~~^~~~~~~~
/usr/include/c++/12.2.1/bits/shared_ptr_base.h:1819:5: note: candidate: 'template<class _Tp, __gnu_cxx::_Lock_policy _Lp> bool std::operator==(nullptr_t, const __shared_ptr<_Tp, _Lp>&)'
 1819 |     operator==(nullptr_t, const __shared_ptr<_Tp, _Lp>& __a) noexcept
      |     ^~~~~~~~
/usr/include/c++/12.2.1/bits/shared_ptr_base.h:1819:5: note:   template argument deduction/substitution failed:
/usr/include/c++/12.2.1/bits/stl_list.h:2137:56: note:   'const MyObject' is not derived from 'const std::__shared_ptr<_Tp, _Lp>'
 2137 |       while (__i1 != __end1 && __i2 != __end2 && *__i1 == *__i2)
      |                                                  ~~~~~~^~~~~~~~
/usr/include/c++/12.2.1/bits/shared_ptr.h:555:5: note: candidate: 'template<class _Tp, class _Up> bool std::operator==(const shared_ptr<_Tp>&, const shared_ptr<_Tp>&)'
  555 |     operator==(const shared_ptr<_Tp>& __a, const shared_ptr<_Up>& __b) noexcept
      |     ^~~~~~~~
/usr/include/c++/12.2.1/bits/shared_ptr.h:555:5: note:   template argument deduction/substitution failed:
/usr/include/c++/12.2.1/bits/stl_list.h:2137:56: note:   'const MyObject' is not derived from 'const std::shared_ptr<_Tp>'
 2137 |       while (__i1 != __end1 && __i2 != __end2 && *__i1 == *__i2)
      |                                                  ~~~~~~^~~~~~~~
/usr/include/c++/12.2.1/bits/shared_ptr.h:561:5: note: candidate: 'template<class _Tp> bool std::operator==(const shared_ptr<_Tp>&, nullptr_t)'
  561 |     operator==(const shared_ptr<_Tp>& __a, nullptr_t) noexcept
      |     ^~~~~~~~
/usr/include/c++/12.2.1/bits/shared_ptr.h:561:5: note:   template argument deduction/substitution failed:
/usr/include/c++/12.2.1/bits/stl_list.h:2137:56: note:   'const MyObject' is not derived from 'const std::shared_ptr<_Tp>'
 2137 |       while (__i1 != __end1 && __i2 != __end2 && *__i1 == *__i2)
      |                                                  ~~~~~~^~~~~~~~
/usr/include/c++/12.2.1/bits/shared_ptr.h:582:5: note: candidate: 'template<class _Tp> bool std::operator==(nullptr_t, const shared_ptr<_Tp>&)'
  582 |     operator==(nullptr_t, const shared_ptr<_Tp>& __a) noexcept
      |     ^~~~~~~~
/usr/include/c++/12.2.1/bits/shared_ptr.h:582:5: note:   template argument deduction/substitution failed:
/usr/include/c++/12.2.1/bits/stl_list.h:2137:56: note:   'const MyObject' is not derived from 'const std::shared_ptr<_Tp>'
 2137 |       while (__i1 != __end1 && __i2 != __end2 && *__i1 == *__i2)
      |                                                  ~~~~~~^~~~~~~~
/usr/include/c++/12.2.1/bits/stl_list.h:2124:5: note: candidate: 'template<class _Tp, class _Alloc> bool std::operator==(const __cxx11::list<_Tp, _Alloc>&, const __cxx11::list<_Tp, _Alloc>&)'
 2124 |     operator==(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
      |     ^~~~~~~~
/usr/include/c++/12.2.1/bits/stl_list.h:2124:5: note:   template argument deduction/substitution failed:
/usr/include/c++/12.2.1/bits/stl_list.h:2137:56: note:   'const MyObject' is not derived from 'const std::__cxx11::list<_Tp, _Alloc>'
 2137 |       while (__i1 != __end1 && __i2 != __end2 && *__i1 == *__i2)
      |                                                  ~~~~~~^~~~~~~~
In file included from /usr/include/c++/12.2.1/bits/ios_base.h:46,
                 from /usr/include/c++/12.2.1/ios:42:
/usr/include/c++/12.2.1/system_error:362:3: note: candidate: 'bool std::operator==(const error_code&, const error_code&)'
  362 |   operator==(const error_code& __lhs, const error_code& __rhs) noexcept
      |   ^~~~~~~~
/usr/include/c++/12.2.1/system_error:362:32: note:   no known conversion for argument 1 from 'const MyObject' to 'const std::error_code&'
  362 |   operator==(const error_code& __lhs, const error_code& __rhs) noexcept
      |              ~~~~~~~~~~~~~~~~~~^~~~~
/usr/include/c++/12.2.1/system_error:368:3: note: candidate: 'bool std::operator==(const error_code&, const error_condition&)'
  368 |   operator==(const error_code& __lhs, const error_condition& __rhs) noexcept
      |   ^~~~~~~~
/usr/include/c++/12.2.1/system_error:368:32: note:   no known conversion for argument 1 from 'const MyObject' to 'const std::error_code&'
  368 |   operator==(const error_code& __lhs, const error_condition& __rhs) noexcept
      |              ~~~~~~~~~~~~~~~~~~^~~~~
/usr/include/c++/12.2.1/system_error:376:3: note: candidate: 'bool std::operator==(const error_condition&, const error_condition&)'
  376 |   operator==(const error_condition& __lhs,
      |   ^~~~~~~~
/usr/include/c++/12.2.1/system_error:376:37: note:   no known conversion for argument 1 from 'const MyObject' to 'const std::error_condition&'
  376 |   operator==(const error_condition& __lhs,
      |              ~~~~~~~~~~~~~~~~~~~~~~~^~~~~
/usr/include/c++/12.2.1/system_error:408:3: note: candidate: 'bool std::operator==(const error_condition&, const error_code&)'
  408 |   operator==(const error_condition& __lhs, const error_code& __rhs) noexcept
      |   ^~~~~~~~
/usr/include/c++/12.2.1/system_error:408:37: note:   no known conversion for argument 1 from 'const MyObject' to 'const std::error_condition&'
  408 |   operator==(const error_condition& __lhs, const error_code& __rhs) noexcept
      |              ~~~~~~~~~~~~~~~~~~~~~~~^~~~~
In file included from /usr/include/c++/12.2.1/bits/stl_algobase.h:71:
/usr/include/c++/12.2.1/bits/predefined_ops.h: In instantiation of 'constexpr bool __gnu_cxx::__ops::_Iter_less_iter::operator()(_Iterator1, _Iterator2) const [with _Iterator1 = std::_List_const_iterator<MyObject>; _Iterator2 = std::_List_const_iterator<MyObject>]':
/usr/include/c++/12.2.1/bits/stl_algobase.h:1294:14:   required from 'bool std::__lexicographical_compare_impl(_II1, _II1, _II2, _II2, _Compare) [with _II1 = _List_const_iterator<MyObject>; _II2 = _List_const_iterator<MyObject>; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
/usr/include/c++/12.2.1/bits/stl_algobase.h:1311:46:   required from 'static bool std::__lexicographical_compare<_BoolType>::__lc(_II1, _II1, _II2, _II2) [with _II1 = std::_List_const_iterator<MyObject>; _II2 = std::_List_const_iterator<MyObject>; bool _BoolType = false]'
/usr/include/c++/12.2.1/bits/stl_algobase.h:1382:60:   required from 'bool std::__lexicographical_compare_aux1(_II1, _II1, _II2, _II2) [with _II1 = _List_const_iterator<MyObject>; _II2 = _List_const_iterator<MyObject>]'
/usr/include/c++/12.2.1/bits/stl_algobase.h:1416:49:   required from 'bool std::__lexicographical_compare_aux(_II1, _II1, _II2, _II2) [with _II1 = _List_const_iterator<MyObject>; _II2 = _List_const_iterator<MyObject>]'
/usr/include/c++/12.2.1/bits/stl_algobase.h:1746:48:   required from 'bool std::lexicographical_compare(_II1, _II1, _II2, _II2) [with _II1 = _List_const_iterator<MyObject>; _II2 = _List_const_iterator<MyObject>]'
/usr/include/c++/12.2.1/bits/stl_list.h:2182:42:   [ skipping 4 instantiation contexts, use -ftemplate-backtrace-limit=0 to disable ]
/myproj/libs/sol/sol.hpp:23333:25:   required from 'void sol::detail::insert_default_registrations(IFx&&, Fx&&) [with T = MyObjContainer; IFx = sol::u_detail::register_usertype<MyObjContainer, sol::automagic_flags::all>(lua_State*, sol::automagic_enrollments)::<lambda(lua_State*, sol::u_detail::submetatable_type, sol::stateless_reference&)>::<lambda(sol::meta_function, lua_CFunction)>&; Fx = properties_enrollment_allowed&]'
/myproj/libs/sol/sol.hpp:24493:43:   required from 'int sol::u_detail::register_usertype(lua_State*, sol::automagic_enrollments) [with T = MyObjContainer; sol::automagic_flags enrollment_flags = sol::automagic_flags::all; lua_State = lua_State]'
/myproj/libs/sol/sol.hpp:26490:70:   required from 'sol::usertype<Class> sol::basic_table_core<<anonymous>, <template-parameter-1-2> >::new_usertype(Key&&, sol::constant_automagic_enrollments<enrollment_flags>) [with Class = MyObjContainer; Key = const char (&)[8]; sol::automagic_flags enrollment_flags = sol::automagic_flags::all; bool top_level = true; ref_t = sol::basic_reference<false>; sol::usertype<Class> = sol::basic_usertype<MyObjContainer, sol::basic_reference<false> >]'
/myproj/libs/sol/sol.hpp:26516:49:   required from 'sol::usertype<Class> sol::basic_table_core<<anonymous>, <template-parameter-1-2> >::new_usertype(Key&&, Arg&&, Args&& ...) [with Class = MyObjContainer; Key = const char (&)[8]; Arg = const sol::base_list<>&; Args = {sol::base_list<std::__cxx11::list<MyObject, std::allocator<MyObject> > >, const char (&)[4], void (MyObjContainer::*)(int, int)}; <template-parameter-2-5> = void; bool top_level = true; ref_t = sol::basic_reference<false>; sol::usertype<Class> = sol::basic_usertype<MyObjContainer, sol::basic_reference<false> >]'
/myproj/libs/sol/sol.hpp:27984:37:   required from 'sol::usertype<Class> sol::state_view::new_usertype(Args&& ...) [with Class = MyObjContainer; Args = {const char (&)[8], const sol::base_list<>&, sol::base_list<std::__cxx11::list<MyObject, std::allocator<MyObject> > >, const char (&)[4], void (MyObjContainer::*)(int, int)}; sol::usertype<Class> = sol::basic_usertype<MyObjContainer, sol::basic_reference<false> >]'
/myproj/mytest.cpp:21:37:   required from here
/usr/include/c++/12.2.1/bits/predefined_ops.h:45:23: error: no match for 'operator<' (operand types are 'const MyObject' and 'const MyObject')
   45 |       { return *__it1 < *__it2; }
      |                ~~~~~~~^~~~~~~~
/usr/include/c++/12.2.1/bits/stl_iterator.h:1246:5: note: candidate: 'template<class _IteratorL, class _IteratorR, class _Container> bool __gnu_cxx::operator<(const __normal_iterator<_IteratorL, _Container>&, const __normal_iterator<_IteratorR, _Container>&)'
 1246 |     operator<(const __normal_iterator<_IteratorL, _Container>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/12.2.1/bits/stl_iterator.h:1246:5: note:   template argument deduction/substitution failed:
/usr/include/c++/12.2.1/bits/predefined_ops.h:45:23: note:   'const MyObject' is not derived from 'const __gnu_cxx::__normal_iterator<_IteratorL, _Container>'
   45 |       { return *__it1 < *__it2; }
      |                ~~~~~~~^~~~~~~~
/usr/include/c++/12.2.1/bits/stl_iterator.h:1254:5: note: candidate: 'template<class _Iterator, class _Container> bool __gnu_cxx::operator<(const __normal_iterator<_Iterator, _Container>&, const __normal_iterator<_Iterator, _Container>&)'
 1254 |     operator<(const __normal_iterator<_Iterator, _Container>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/12.2.1/bits/stl_iterator.h:1254:5: note:   template argument deduction/substitution failed:
/usr/include/c++/12.2.1/bits/predefined_ops.h:45:23: note:   'const MyObject' is not derived from 'const __gnu_cxx::__normal_iterator<_Iterator, _Container>'
   45 |       { return *__it1 < *__it2; }
      |                ~~~~~~~^~~~~~~~
ninja: build stopped: subcommand failed.

I don't understand why it's requiring additional operators, since they are not requested when exposing std::list<MyObject> directly in this way: https://github.com/ThePhD/sol2/issues/773#issuecomment-463550908.

I just need an additional method, could this be so difficult? What am I missing? Is there a way to achieve what I need?

I found this alternative here (via composition): https://github.com/ThePhD/sol2/blob/develop/examples/source/container_usertype_as_container.cpp but I would like to avoid having to explicitly wrap all methods and types of the underlying container if possible, since I just need to go in "addition" to them.