nana icon indicating copy to clipboard operation
nana copied to clipboard

fundamental types needs move constructors

Open ilAYAli opened this issue 5 years ago • 3 comments

This does not work:

 std::vector<nana::inputbox::integer> items;
 items.emplace_back(nana::inputbox::integer{ "foo", 42, 1, 1000, 1 });

As no move constructor is available for the nana fundamental types, and all of these contain: std::unique_ptr<implement> impl_;

ilAYAli avatar Aug 02 '19 13:08 ilAYAli

https://sourceforge.net/p/nanapro/blog/2013/05/why-should-not-a-widget-be-copyable-or-movable/ try: std::vector<std::unique_ptr<nana::inputbox::integer>> items;

qPCR4vir avatar Aug 02 '19 22:08 qPCR4vir

Indeed, the devil is in the details. However your suggested fix did not solve the problem:

Severity	Code	Description	Project	File	Line	Suppression State
Error	C2664	 'std::unique_ptr<nana::inputbox::integer,std::default_delete<_Ty>>::unique_ptr(const std::unique_ptr<_Ty,std::default_delete<_Ty>> &)': cannot convert argument 1 from '_Ty' to 'std::nullptr_t'
        with
        [
            _Ty=nana::inputbox::integer
        ]	ds2	C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.22.27905\include\xmemory	761	

Severity	Code	Description	Project	File	Line	Suppression State
Error	C2440	 'initializing': cannot convert from '_Ty' to '_Objty'
        with
        [
            _Ty=std::unique_ptr<nana::inputbox::integer,std::default_delete<nana::inputbox::integer>> *
        ]
        and
        [
            _Objty=nana::inputbox::abstract_content *
        ]	ds2	C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.22.27905\include\xmemory	761	

ilAYAli avatar Aug 02 '19 22:08 ilAYAli

Thanks for your feedback! As @qPCR4vir mentioned, a widget should not be copyable and movable. But I checked the implementations of inputbox::integer/boolean/text/... classes, they can be designed to be movable.

A workaround, use deque/list, because nana::inputbox::integer has std::unique_ptr member which is not copyable.

 std::deque<nana::inputbox::integer> items;
 items.emplace_back( "foo", 42, 1, 1000, 1 );

cnjinhao avatar Aug 05 '19 02:08 cnjinhao