mirror of
https://github.com/dlang/dmd.git
synced 2025-05-04 00:53:20 +03:00
Allow -preview=in
only with extern(D|C++)
The intent of `-preview=in` is to make `in` the go-to storage class for input parameters in D. However it is D centric, as it is an enhanced version of `scope const ref`. As non-`extern(D)` functions usually are expected to match a specific ABI, using `in` is hardly a good idea. However, as C++, also have a "go to" storage class for input parameters (`const T&`), `in` can also be applied on `extern(C++)` function in order to bind to `const T&` parameters. This also allows to expose a closer API for a function than via `const ref`, as `in` will allow to bind rvalues to `const T&`, as in C++.
This commit is contained in:
parent
37436a4446
commit
b3cc517966
5 changed files with 75 additions and 23 deletions
|
@ -4,30 +4,8 @@
|
|||
#include <exception>
|
||||
#include <cstdarg>
|
||||
|
||||
#if _WIN32 // otherwise defined in C header files!
|
||||
// https://issues.dlang.org/show_bug.cgi?id=18955
|
||||
namespace std
|
||||
{
|
||||
template<typename Char>
|
||||
struct char_traits
|
||||
{
|
||||
};
|
||||
template<typename Char>
|
||||
class allocator
|
||||
{
|
||||
};
|
||||
template<typename Char, typename Traits, typename Alloc>
|
||||
class basic_string
|
||||
{
|
||||
};
|
||||
typedef basic_string<char, char_traits<char>, allocator<char> > string;
|
||||
}
|
||||
#else // if POSIX
|
||||
|
||||
#include <string>
|
||||
|
||||
#endif // _WIN32
|
||||
|
||||
#include "cppb.h"
|
||||
|
||||
/**************************************/
|
||||
|
@ -936,3 +914,11 @@ void test18955()
|
|||
callback18955(s);
|
||||
#endif
|
||||
}
|
||||
|
||||
void previewInFunction(const int& a, const std::string& b, const std::string& c);
|
||||
|
||||
void testPreviewIn()
|
||||
{
|
||||
std::string s = "Hello World";
|
||||
previewInFunction(42, s, s);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue