From: <wsf...@us...> - 2012-09-25 19:25:21
|
Revision: 13850 http://swig.svn.sourceforge.net/swig/?rev=13850&view=rev Author: wsfulton Date: 2012-09-25 19:25:14 +0000 (Tue, 25 Sep 2012) Log Message: ----------- Update on C++11 user-defined literal status Modified Paths: -------------- branches/gsoc2009-matevz/Doc/Manual/Cpp0x.html branches/gsoc2009-matevz/Examples/test-suite/cpp0x_userdefined_literals.i Modified: branches/gsoc2009-matevz/Doc/Manual/Cpp0x.html =================================================================== --- branches/gsoc2009-matevz/Doc/Manual/Cpp0x.html 2012-09-21 19:15:44 UTC (rev 13849) +++ branches/gsoc2009-matevz/Doc/Manual/Cpp0x.html 2012-09-25 19:25:14 UTC (rev 13850) @@ -516,19 +516,50 @@ <H3><a name="Cpp0x_User_defined_literals"></a>7.2.19 User-defined literals</H3> -<p>SWIG correctly parses the new <tt>operator""_mysuffix()</tt> functions.</p> +<p> +SWIG parses the declaration of user-defined literals, that is, the <tt>operator "" _mysuffix()</tt> function syntax. +</p> +<p> +Some examples are the raw literal: +</p> <div class="code"><pre> +OutputType operator "" _myRawLiteral(const char * value); +</pre></div> + +<p> +numeric cooked literals: +</p> +<div class="code"><pre> +OutputType operator "" _mySuffixIntegral(unsigned long long); +OutputType operator "" _mySuffixFloat(long double); +</pre></div> + +<p> +and cooked string literals: +</p> +<div class="code"><pre> OutputType operator "" _mySuffix(const char * string_values, size_t num_chars); OutputType operator "" _mySuffix(const wchar_t * string_values, size_t num_chars); OutputType operator "" _mySuffix(const char16_t * string_values, size_t num_chars); OutputType operator "" _mySuffix(const char32_t * string_values, size_t num_chars); -OutputType operator "" _mySuffix(int value); </pre></div> -<p>The %rename currently doesn't parse the double quotes. Please -rename the functions in the code using the #define preprocessor directive.</p> +<p> +Note that the %rename directive currently does not parse the double quotes, so these can't be easily accessed from +target languages. +</p> +<p> +Use of user-defined literals such as the following still give a syntax error: +</p> + +<div class="code"><pre> +OutputType var1 = "1234"_suffix; +OutputType var2 = 1234_suffix; +OutputType var3 = 3.1416_suffix; +</pre></div> + <H3><a name="Cpp0x_Thread_local_storage"></a>7.2.20 Thread-local storage</H3> Modified: branches/gsoc2009-matevz/Examples/test-suite/cpp0x_userdefined_literals.i =================================================================== --- branches/gsoc2009-matevz/Examples/test-suite/cpp0x_userdefined_literals.i 2012-09-21 19:15:44 UTC (rev 13849) +++ branches/gsoc2009-matevz/Examples/test-suite/cpp0x_userdefined_literals.i 2012-09-25 19:25:14 UTC (rev 13850) @@ -1,5 +1,5 @@ /* This testcase checks whether SWIG correctly parses the user-defined literals - for the string introduced in C++0x. */ + introduced in C++0x. */ %module cpp0x_userdefined_literals %inline %{ @@ -7,18 +7,20 @@ struct OutputType { int val; - - OutputType(int v) { v=val; } + OutputType(int v) : val(v) {} }; -/* Note: GCC doesn't support user-defined literals yet! */ -struct TT { -OutputType operator "" (const char * string_values, size_t num_chars) { return OutputType(100); } +// Raw literal +OutputType operator "" _myRawLiteral(const char * value) { return OutputType(10); } + +// Cooked numeric literals +OutputType operator "" _mySuffixIntegral(unsigned long long) { return OutputType(20); } +OutputType operator "" _mySuffixFloat(long double) { return OutputType(30); } + +// Cooked string literals OutputType operator "" _mySuffix1(const char * string_values, size_t num_chars) { return OutputType(100); } OutputType operator "" _mySuffix2(const wchar_t * string_values, size_t num_chars) { return OutputType(200); } OutputType operator "" _mySuffix3(const char16_t * string_values, size_t num_chars) { return OutputType(300); } OutputType operator "" _mySuffix4(const char32_t * string_values, size_t num_chars) { return OutputType(400); } -OutputType operator "" _mySuffix5(int value) /* cooked version - ie. atoi() of string */ { return OutputType(500); } -}; %} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |