C++11 constexpr variables support added
This commit is contained in:
parent
348caba6e5
commit
e186dc13b7
3 changed files with 36 additions and 15 deletions
|
|
@ -107,7 +107,7 @@ For example, ignore the move constructor:
|
|||
</pre></div>
|
||||
|
||||
<p>
|
||||
The plan is to ignore them by default in a future version of SWIG. Note that both normal assignment operators as well as move assignment operators are ignored by default in most target languages with the following warning:
|
||||
The plan is to ignore move constructors by default in a future version of SWIG. Note that both normal assignment operators as well as move assignment operators are ignored by default in most target languages with the following warning:
|
||||
</p>
|
||||
|
||||
<div class="shell">
|
||||
|
|
@ -120,20 +120,19 @@ example.i:18: Warning 503: Can't wrap 'operator =' unless renamed to a valid ide
|
|||
<H3><a name="CPlusPlus11_generalized_constant_expressions"></a>7.2.2 Generalized constant expressions</H3>
|
||||
|
||||
|
||||
<p>SWIG correctly parses the keyword <tt>constexpr</tt>, but ignores its functionality. Constant functions cannot be used as constants.</p>
|
||||
<p>SWIG parses and identifies the keyword <tt>constexpr</tt>, but cannot fully utilise it.
|
||||
These C++ compile time constants are usable as runtime constants from the target languages.
|
||||
Below shows example usage for assigning a C++ compile time constant from a compile time constant function:
|
||||
</p>
|
||||
|
||||
<div class="code"><pre>
|
||||
constexpr int myConstFunc() { return 10; }
|
||||
const int a = myConstFunc(); // results in error
|
||||
constexpr int XXX() { return 10; }
|
||||
constexpr int YYY = XXX() + 100;
|
||||
</pre></div>
|
||||
|
||||
<p>Users needs to use values or predefined constants when defining the new constant value:</p>
|
||||
|
||||
<div class="code"><pre>
|
||||
#define MY_CONST 10
|
||||
constexpr int myConstFunc() { return MY_CONST; }
|
||||
const int a = MY_CONST; // ok
|
||||
</pre></div>
|
||||
<p>
|
||||
When either of these is used from a target language, a runtime call is made to obtain the underlying constant.
|
||||
</p>
|
||||
|
||||
<H3><a name="CPlusPlus11_extern_template"></a>7.2.3 Extern template</H3>
|
||||
|
||||
|
|
|
|||
|
|
@ -4,9 +4,31 @@
|
|||
%module cpp11_constexpr
|
||||
|
||||
%inline %{
|
||||
class TestClass {
|
||||
public:
|
||||
constexpr int func() { return 10; }
|
||||
constexpr int AAA = 10;
|
||||
constexpr const int BBB = 20;
|
||||
constexpr int CCC() { return 30; }
|
||||
constexpr const int DDD() { return 40; }
|
||||
|
||||
constexpr int XXX() { return 10; }
|
||||
constexpr int YYY = XXX() + 100;
|
||||
|
||||
struct ConstExpressions {
|
||||
static constexpr const int JJJ = 100;
|
||||
static constexpr int KKK = 200;
|
||||
static const int LLL = 300;
|
||||
constexpr int MMM() { return 400; }
|
||||
constexpr const int NNN() { return 500; }
|
||||
};
|
||||
%}
|
||||
|
||||
%{
|
||||
int Array10[AAA];
|
||||
int Array20[BBB];
|
||||
int Array30[CCC()];
|
||||
int Array40[DDD()];
|
||||
int Array100[ConstExpressions::JJJ];
|
||||
int Array200[ConstExpressions::KKK];
|
||||
int Array300[ConstExpressions::LLL];
|
||||
//int Array400[ConstExpressions::MMM()];
|
||||
//int Array500[ConstExpressions::NNN()];
|
||||
%}
|
||||
|
|
|
|||
|
|
@ -412,7 +412,7 @@ static void add_symbols(Node *n) {
|
|||
} else {
|
||||
ty = type;
|
||||
}
|
||||
if (!SwigType_ismutable(ty)) {
|
||||
if (!SwigType_ismutable(ty) || (storage && Strstr(storage, "constexpr"))) {
|
||||
SetFlag(n,"hasconsttype");
|
||||
SetFlag(n,"feature:immutable");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue