The macro BOOST_IDL_PROTECT is used to prevent commas within a type expression from being interpretted as macro argument separators by the preprocessor.
<boost/interfaces.hpp><boost/interfaces/detail/idl/protect.hpp>BOOST_IDL_PROTECT#define BOOST_IDL_PROTECT(expr) ...
| expr | - | A parenthesized expression of the form (type_expr) |
The macro BOOST_IDL_PROTECT is used to prevent commas within a type expression from being interpretted as macro argument separators by the preprocessor.
If type_expr denotes a type T, BOOST_IDL_PROTECT((type_expr)) expands to an expression denoting the decayed type of T. The decayed type of T is usually the same as T, but can differ from T if T involves array or function types or has top-level cv-qualification.
Consider the following pseudocode definition:
template<typename Ch, typename Tr, typename Alloc> interface INamed { std::basic_string<Ch, Tr, Alloc> name() const; };
An initial attempt to render the above using the IDL might be as follows:
template<typename Ch, typename Tr, typename Alloc> BOOST_IDL_BEGIN3(INamed) BOOST_IDL_CONST_FN0(name, std::basic_string<Ch, Tr, Alloc>) BOOST_IDL_END3(INamed)
Unfortunately, the preprocessor interprets the third line as an invocation of the macro BOOST_IDL_CONST_FN0 with four arguments:
name
std::basic_string<Ch
Tr
Alloc>
This is an error, since BOOST_IDL_CONST_FN0 takes only two arguments.
The solution, using BOOST_IDL_PROTECT, is as follows:
template<typename Ch, typename Tr, typename Alloc> BOOST_IDL_BEGIN3(INamed) BOOST_IDL_CONST_FN0( name, BOOST_IDL_PROTECT((std::basic_string<Ch, Tr, Alloc>)) ) BOOST_IDL_END3(INamed)
(Note the double parentheses around the expression std::basic_string<Ch, Tr, Alloc>.)
Revised 13 Jan, 2005
© Copyright Jonathan Turkanis, 2005. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Sha'arei Tefila, an Orthodox Shul (Synagogue) in Salt Lake City, Utah Chabad Lubavitch of Utah