www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Argument of template as method of the object (How to replace the macros)

reply unDEFER <undefer gmail.com> writes:
Hello!
Say me please, what the best way to replace the next C++ macros (code from
BerkeleyDB) in D:

#define	WRAPPED_CLASS(_WRAPPER_CLASS, _IMP_CLASS, _WRAPPED_TYPE)           \
	class _IMP_CLASS {};                                               \
									   \
	inline _WRAPPED_TYPE *unwrap(_WRAPPER_CLASS *val)                  \
	{                                                                  \
		if (!val) return (0);                                      \
		return (val->get_##_WRAPPED_TYPE());                       \
	}                                                                  \
									   \
	inline const _WRAPPED_TYPE *unwrapConst(const _WRAPPER_CLASS *val) \
	{                                                                  \
		if (!val) return (0);                                      \
		return (val->get_const_##_WRAPPED_TYPE());                 \
	}

I'm already search several hours but can't find good example in the
documentation.
Thank you in advance.
Oct 29 2011
parent reply Kagamin <spam here.lot> writes:
unDEFER Wrote:

 Hello!
 Say me please, what the best way to replace the next C++ macros (code from
 BerkeleyDB) in D:
 
 #define	WRAPPED_CLASS(_WRAPPER_CLASS, _IMP_CLASS, _WRAPPED_TYPE)           \
 	class _IMP_CLASS {};                                               \
 									   \
 	inline _WRAPPED_TYPE *unwrap(_WRAPPER_CLASS *val)                  \
 	{                                                                  \
 		if (!val) return (0);                                      \
 		return (val->get_##_WRAPPED_TYPE());                       \
 	}                                                                  \
 									   \
 	inline const _WRAPPED_TYPE *unwrapConst(const _WRAPPER_CLASS *val) \
 	{                                                                  \
 		if (!val) return (0);                                      \
 		return (val->get_const_##_WRAPPED_TYPE());                 \
 	}
 
 I'm already search several hours but can't find good example in the
 documentation.
 Thank you in advance.

try val.get!(_WRAPPED_TYPE)
Oct 29 2011
parent unDEFER <unDEFER gmail.com> writes:
Kagamin wrote:

 try
 val.get!(_WRAPPED_TYPE)

Oh, yes, it will works. Big thanks. I just started my practice with D, and yet don't accustomed to its way, but it is great. Thank you again!
Oct 29 2011