Opened 9 years ago
Closed 8 years ago
#9444 closed Feature Requests (fixed)
TTI: support has_member_function on non-class types
| Reported by: | Owned by: | Edward Diener | |
|---|---|---|---|
| Milestone: | To Be Determined | Component: | tti |
| Version: | Boost 1.55.0 | Severity: | Not Applicable |
| Keywords: | Cc: |
Description
Hello again
Would it be possible to support has_member_function on non-class types? It would help with making more generic code:
BOOST_TTI_HAS_MEMBER_FUNCTION(Something)
template<typename T>
class Test
{
public:
static const bool value = has_member_function_Something<T, void>::value;
};
class Empty
{
};
int main(int argc, char *argv[])
{
const bool intHasSomething = Test<int>::value; // fails to compile
const bool classHasSomething = Test<Empty>::value; // ok
return 0;
}
Right now I use a little wrapper around BOOST_TTI_HAS_MEMBER_FUNCTION to create another metafunction that checks for class type. Something like:
#define MY_HAS_MEMBER_FUNCTION(name) \
BOOST_TTI_HAS_MEMBER_FUNCTION(name) \
template<typename T, typename RET, typename ARGS = Boost::mpl::vector<>, typename CV = Boost::function_types::null_tag> \
class HasMemberFunction_##name : public \
Boost::mpl::and_<Boost::is_class<T>, has_member_function_##name<T, RET, ARGS, CV> >::type {};
The downside of this is that it rules out using the member-function-pointer-type model.
Hopefully something could be put in to the metafunction generation to do something similar and not have the downside?
has_static_member_function doesn't have the restriction on class type, which is nice.
Thanks in advance!
Luke Elliott.
Change History (5)
comment:1 by , 9 years ago
comment:3 by , 9 years ago
I have updated the 'develop' branch of the modular Boost git repository to fix this problem. The fix includes testing for the enclosing type being a valid non-class type in all metafunctions. For the query metafunctions if the enclosing type is a valid non-class type, the metafunction always returns 'false'. For the metafunction generated by BOOST_TTI_MEMBER_TYPE if the enclosing type is a valid non-class type, the metafunction always returns the marker type. This is also explained in the updated documentation.
comment:4 by , 8 years ago
This fix was merged into the 'master' branch in late February and will go into the 1.56 release.
comment:5 by , 8 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |

I will be working to add to all of the TTI metafunctions the ability to handle a non-class as the enclosing type, in which case the metafunction should return a value of 'false' rather than give a compiler error. For the member_type metafunction a non-class enclosing type will always generate the default type or the user-defined default type rather than give an error.