Re: Constructor missing in Swig4.0 new std_vector.i ?

William S Fulton <[email protected]>
Newsgroups gmane.comp.programming.swig
Message-ID <CANGqftA4sD9au4JcdJU-J=aZ-1qiRsJphq-FVX_2RRsF6-7GNQ@mail.gmail.com>
This is covered in the CHANGES file...

2019-02-28: wsfulton
            [Java] std::vector improvements for types that do not have a
default constructor.

            The std::vector wrappers have been changed to work by default
for elements that are
            not default insertable, i.e. have no default constructor. This
has been achieved by
            not wrapping:

              vector(size_type n);

            Previously the above had to be ignored via %ignore.

            If the above constructor is still required it can be added back
in again via %extend:

              %extend std::vector {
                vector(size_type count) { return new std::vector< T
>(count); }
              }

            Alternatively, the following wrapped constructor could be used
as it provides near-enough
            equivalent functionality:

              vector(jint count, const value_type& value);

If you want to cover different versions of SWIG, use the SWIG_VERSION
macro...

#if SWIG_VERSION >= 0x040000
              %extend std::vector {
                vector(size_type count) { return new std::vector< T
>(count); }
              }
#endif

William

On Wed, 11 Mar 2020 at 14:07, Jean-Max Redonnet <[email protected]> wrote:

> Hi,
>
> I am using Swig to wrap a C++ library with Java.
>
> With Swig3.0, I used to write
> %template(MyClass) vector<namespace::EnumType>;
> and that's all. A fully functional MyClass was created.
>
> Using Swig4.0, compilation still works but I lack the simple constructor
> vector(size_type n);
>
> Indeed, comparing std_vector.i files make appear this constructor is no
> longer present in Swig4.0:
> Swig3.0 std_vector.i  (extract)
>       vector();
>       vector(size_type n);
>       size_type size() const;
>       size_type capacity() const;
>
> Swig4.0 std_vector.i  (extract)
>       vector();
>       vector(const vector &other);
>
>       size_type capacity() const;
>
> I probably miss something but reading the documentation doesn't really
> help me (I'm not very familiar with C++, nor Swig).
>
> Any hint to solve this problem would be really appreciated. And a solution
> that works for both Swig 4.0 and Swig 3.0 would be ideal (I work with
> people that still use Swig 3.0)
>
> In advance, Thanks for any help.
>
> jMax
> _______________________________________________
> Swig-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/swig-user
>

_______________________________________________
Swig-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/swig-user
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.