Re:D Language accepted for inclusion in GCC
by _yosefk on Wednesday June 21, 2017 @11:17AM
(#14604517)
Most useful C++ code is either not templates or it's templates which can be instantiated a finite number of times and then used like non-templated code. Most "header-only"/header-heavy C++ libraries which present the problem you mention solve problems like C++'s smart for loop working like "for x in xs" does in Python but not working like "for x,y in zip(xs,ys)" does or like "for i,x for enumerate(xs)" does etc.; you don't really need these outside C++ (whether you need them inside C++ is another question but it's irrelevant here.)
[ Parent
| on HN ]
Re:D Language accepted for inclusion in GCC
by CJefferson on Wednesday June 21, 2017 @11:27AM
(#14604599)
That sounds ..wrong. what about the C++ standard library? Neither vector or sort sounds like that?
Re:D Language accepted for inclusion in GCC
by yorwba on Wednesday June 21, 2017 @11:37AM
(#14604700)
Those > can be instantiated a finite number of times and then used like non-templated code.
So you have a C++ file that uses vector<int>, vector<struct c_struct>, vector<CppClass>, vector<DClass>, etc. once and then you can link to them from D code.
The only case where that doesn't work is when you have lots of one-off instantiations, where requiring an instantiation in C++ code for each use in D would get annoying quickly.
Re:D Language accepted for inclusion in GCC
by amelius on Wednesday June 21, 2017 @12:13PM
(#14605054)
Does the D compiler know how to mangle/demangle C++ names?
Do you have to write some kind of D header file for foreign C++ functions? Otherwise, how would D even know about the existence of e.g. vector<int>::push?
Re:D Language accepted for inclusion in GCC
by biotronic on Wednesday June 21, 2017 @12:24PM
(#14605186)
https://dlang.org/spec/cpp_interface.html#cpp-templates
You will need to recreate the C++ function definitions in D and mark them extern(C++), but that's about it.