On Tue, Jun 25, 2019 at 3:23 PM denisgolovan <denisgolo...@yandex.ru> wrote:

> e.g. what about returning dynamic arrays? Like:
>
> type TIntArray = array of Integer;
> function ArrInit(): TIntArray;
> begin
>   SetLength(Result, 1);
>   Result[0]:=1;
> end;
>

Stuff like that is pretty much impossible, because you can't dynamically
allocate memory at compile time.

See here
<https://godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(j:1,lang:c%2B%2B,source:'%23include+%3Ciostream%3E%0A%23include+%3Cmemory%3E%0A%23include+%3Cvector%3E%0A%23include+%3Cstring%3E%0A%0Ausing+std::cout%3B%0Ausing+std::unique_ptr%3B%0Ausing+std::make_unique%3B%0Ausing+std::vector%3B%0Ausing+std::string%3B%0A%0Atemplate+%3Ctypename+T%3E+using+TVecPtr+%3D+vector%3CT%3E%3B%0A%0Atemplate+%3Ctypename+T%3E+using+TDynArray+%3D+unique_ptr%3CTVecPtr%3CT%3E%3E%3B%0A%0Atemplate+%3Ctypename+T,+typename...+Values%3E%0Aconstexpr+TDynArray%3CT%3E+DynArray(Values...+vals)+%7B%0A++return+make_unique%3CTVecPtr%3CT%3E%3E(vector%3CT%3E%7Bvals...%7D)%3B%0A%7D%0A%0Aint+main()+%7B%0A++const+auto+Strings+%3D+DynArray%3Cstring%3E(%0A++++%22Pascal!'s%22,%0A++++%22real%22,%0A++++%22dynamic%22,%0A++++%22arrays%22,%0A++++%22are%22,%0A++++%22much%22,%0A++++%22nicer!!%22%0A++)%3B%0A++for+(auto+S+:+*Strings)+%7B%0A++++cout+%3C%3C+S+%3C%3C+%22%5Cn%22%3B%0A++%7D%0A%7D'),l:'5',n:'0',o:'C%2B%2B+source+%231',t:'0')),k:50.745098039215684,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:clang_trunk,filters:(b:'0',binary:'1',commentOnly:'0',demangle:'0',directives:'0',execute:'0',intel:'0',libraryCode:'1',trim:'1'),lang:c%2B%2B,libs:!(),options:'-O3',source:1),l:'5',n:'0',o:'x86-64+clang+(trunk)+(Editor+%231,+Compiler+%231)+C%2B%2B',t:'0')),k:49.254901960784316,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4>
for a C++ example. Note how the function being marked constexpr doesn't
actually do anything special in that particular case, and if you try to
initialize the array with "constexpr auto" instead of "const auto", the
whole program just won't compile.
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to