1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363
|
// ==========================================================================
// SeqAn - The Library for Sequence Analysis
// ==========================================================================
// Copyright (c) 2006-2018, Knut Reinert, FU Berlin
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of Knut Reinert or the FU Berlin nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL KNUT REINERT OR THE FU BERLIN BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
//
// ==========================================================================
// Author: Manuel Holtgrewe <manuel.holtgrewe@fu-berlin.de>
// ==========================================================================
// "enable if" functionality.
// ==========================================================================
// SEQAN_NO_GENERATED_FORWARDS
// TODO(holtgrew): Rename *2 Metafunctions to *C metafunctions.
// TODO(holtgrew): Document properly.
#ifndef SEQAN_INCLUDE_SEQAN_BASIC_METAPROGRAMMING_ENABLE_IF_H_
#define SEQAN_INCLUDE_SEQAN_BASIC_METAPROGRAMMING_ENABLE_IF_H_
namespace seqan {
// ============================================================================
// Forwards
// ============================================================================
// ============================================================================
// Tags, Classes, Enums
// ============================================================================
// ============================================================================
// Metafunctions
// ============================================================================
/*!
* @defgroup EnableIfFunctionality Enable-If Functionality
* @brief The metafunctions and macros for enabling/disabling of functions.
*
* The <tt>EnableIf</tt> metafunctions also support the shortcut to <tt>::Type</tt> members as described for the @link
* LogicMetaprogramming logical metaprogramming metafunctions @endlink.
*
* <b>Enable-if is an advanced technique and mostly interesting if you want to extend the SeqAn library with generic
* algorithms. The average developer does not have to know about this technique.</b>.
*
* @see LogicalValuesTags
* @see LogicMetaprogramming
*/
// ----------------------------------------------------------------------------
// Metafunction EnableIf
// ----------------------------------------------------------------------------
/*!
* @mfn EnableIfFunctionality#EnableIf
* @headerfile <seqan/basic.h>
* @brief Metafunction to use for conditionally enabling code.
*
* @signature EnableIf<TBool, T = void>::Type
*
* @tparam TBool The Tag <tt>True</tt> or <tt>False</tt> to use for enabling/disabling.
* @tparam T Dummy, do not set.
*
* @return Type Set to <tt>T</tt>. Only defined if <tt>TBool</tt> is <tt>True</tt>. This triggers the SFINAE behaviour
* in C++ which can be used to enable/disable functions.
*
* Do not use directly but use through the enable if/disable if macros.
*
* @see EnableIfFunctionality#SEQAN_FUNC_ENABLE_IF
* @see EnableIfFunctionality#SEQAN_FUNC_DISABLE_IF
* @see EnableIfFunctionality#SEQAN_CTOR_ENABLE_IF
* @see EnableIfFunctionality#SEQAN_CTOR_DISABLE_IF
*/
template <typename TBool, typename T = void>
struct EnableIf : EnableIf<typename TBool::Type, T> {};
template <typename T>
struct EnableIf<False, T> {};
template <typename T>
struct EnableIf<True, T>
{
typedef T Type;
};
//template <typename T>
//struct EnableIf<False, T> {};
// ----------------------------------------------------------------------------
// Metafunction DisableIf
// ----------------------------------------------------------------------------
/*!
* @mfn EnableIfFunctionality#DisableIf
* @headerfile <seqan/basic.h>
* @brief Metafunction to use for conditionally disabling code.
*
* @signature DisableIf<TBool, T = void>::Type
*
* @tparam TBool The Tag <tt>True</tt> or <tt>False</tt> to use for enabling/disabling.
* @tparam T Dummy, do not set.
*
* @return Type Set to <tt>T</tt>. Only defined if <tt>TBool</tt> is <tt>False</tt>. This triggers the SFINAE behaviour
* in C++ which can be used to enable/disable functions.
*
* Do not use directly but use through the enable if/disable if macros.
*
* @see EnableIfFunctionality#SEQAN_FUNC_ENABLE_IF
* @see EnableIfFunctionality#SEQAN_FUNC_DISABLE_IF
* @see EnableIfFunctionality#SEQAN_CTOR_ENABLE_IF
* @see EnableIfFunctionality#SEQAN_CTOR_DISABLE_IF
*/
template <typename TBool, typename T = void>
struct DisableIf : DisableIf<typename TBool::Type, T> {};
template <typename T>
struct DisableIf<True, T> {};
template <typename T>
struct DisableIf<False, T>
{
typedef T Type;
};
// ----------------------------------------------------------------------------
// Metafunction EnableIf2
// ----------------------------------------------------------------------------
/*!
* @mfn EnableIfFunctionality#EnableIf2
* @headerfile <seqan/basic.h>
* @deprecated Will be renamed to EnableIfC.
* @brief Metafunction to use for conditionally enabling code, bool version.
*
* @signature EnableIf2<BOOL, T = void>::Type
*
* @tparam BOOL The <tt>bool</tt> constant to evaluate for enabling/disabling.
* @tparam T Dummy, do not set.
*
* @return Type Set to <tt>T</tt>. Only defined if <tt>BOOL</tt> is <tt>true</tt>. This triggers the SFINAE behaviour
* in C++ which can be used to enable/disable functions.
*
* Do not use directly but use through the enable if/disable if macros.
*
* @see EnableIfFunctionality#SEQAN_FUNC_ENABLE_IF
* @see EnableIfFunctionality#SEQAN_FUNC_DISABLE_IF
* @see EnableIfFunctionality#SEQAN_CTOR_ENABLE_IF
* @see EnableIfFunctionality#SEQAN_CTOR_DISABLE_IF
*/
//
// Example for enable-if function:
//
// template <typename TContainer>
// typename EnableIf<
// IsContainer<TContainer>, // 1st arg: enable-if condition
// typename Size<TContainer>::Type >::Type // 2nd arg: return type
// length(TContainer & cont)
// {
// SEQAN_CONCEPT_ASSERT((ContainerConcept<TContainer>));
// return end(cont) - begin(cont);
// }
template <bool b, typename T>
struct EnableIf2;
template <bool b, typename T = void>
struct EnableIf2
{
typedef T Type;
};
template <typename T>
struct EnableIf2<false, T> {};
// ----------------------------------------------------------------------------
// Metafunction DisableIf2
// ----------------------------------------------------------------------------
/*!
* @mfn EnableIfFunctionality#DisableIf2
* @headerfile <seqan/basic.h>
* @deprecated Will be renamed to DisableIfC.
* @brief Metafunction to use for conditionally disabling code, bool version.
*
* @signature DisableIf2<BOOL, T = void>::Type
*
* @tparam BOOL The <tt>bool</tt> constant to evaluate for enabling/disabling.
* @tparam T Dummy, do not set.
*
* @return Type Set to <tt>T</tt>. Only defined if <tt>BOOL</tt> is <tt>false</tt>. This triggers the SFINAE behaviour
* in C++ which can be used to enable/disable functions.
*
* Do not use directly but use through the enable if/disable if macros.
*
* @see EnableIfFunctionality#SEQAN_FUNC_ENABLE_IF
* @see EnableIfFunctionality#SEQAN_FUNC_DISABLE_IF
* @see EnableIfFunctionality#SEQAN_CTOR_ENABLE_IF
* @see EnableIfFunctionality#SEQAN_CTOR_DISABLE_IF
*/
template <bool b, typename T>
struct DisableIf2;
template <bool b, typename T = void>
struct DisableIf2
{
typedef T Type;
};
template <typename T>
struct DisableIf2<true, T> {};
} // namespace seqan
// ============================================================================
// Macros
// ============================================================================
/*!
* @macro EnableIfFunctionality#SEQAN_CTOR_ENABLE_IF
* @headerfile <seqan/basic.h>
* @brief Bind the visibility of a constructor to an expression.
*
* @signature SEQAN_CTOR_ENABLE_IF(TCondition);
*
* @param TCondition Boolean type, one of <tt>True</tt> and <tt>False</tt> or a metafunction returning such a tag
* type. If <tt>True</tt> then the constructor is visible, otherwise, it is not.
*
* This macro allows one to bind the visibility of a construtor to a boolean expression by using the <a
* href="http://en.wikipedia.org/wiki/Substitution_failure_is_not_an_error">SFINAE</a> principle for an optional argument with default value. The macro call must be used as the last dummy-argument of a constructor.
*
* To avoid an unused argument warning, call <tt>ignoreUnusedVariableWarning(dummy)</tt> in the constructor's body.
*
* <b>Important:</b> The constructor to enable must be a function template and <tt>TCondition</tt> must include at
* least one template parameter of the function template.
*
* @section Example
*
* The following shows an example on how to properly use <tt>SEQAN_CTOR_ENABLE_IF</tt> as the last argument to the
* constructor and suppressing the unused variable warning for the dummy parameter.
*
* @snippet demos/dox/basic/enable_if.cpp enable if example constructor
*/
#define SEQAN_CTOR_ENABLE_IF(...) typename seqan::EnableIf<__VA_ARGS__>::Type * dummy = 0
/*!
* @macro EnableIfFunctionality#SEQAN_CTOR_DISABLE_IF
* @headerfile <seqan/basic.h>
* @brief Bind the visibility of a constructor to an expression.
*
* @signature SEQAN_CTOR_DISABLE_IF(TCondition);
*
* @param TCondition Boolean type, one of <tt>True</tt> and <tt>False</tt> or a metafunction returning such a tag
* type. If <tt>False</tt> then the constructor is visible, otherwise, it is not.
*
* This macro allows one to bind the visibility of a construtor to a boolean expression by using the <a
* href="http://en.wikipedia.org/wiki/Substitution_failure_is_not_an_error">SFINAE</a> principle for an optional argument with default value. The macro call must be used as the last dummy-argument of a constructor.
*
* To avoid an unused argument warning, call <tt>ignoreUnusedVariableWarning(dummy)</tt> in the constructor's body.
*
* <b>Important:</b> The constructor to disable must be a function template and <tt>TCondition</tt> must include at
* least one template parameter of the function template.
*
* @section Example
*
* The following shows an example on how to properly use <tt>SEQAN_CTOR_DISABLE_IF</tt> as the last argument to the
* constructor and suppressing the unused variable warning for the dummy parameter.
*
* @snippet demos/dox/basic/enable_if.cpp disable if example constructor
*/
#define SEQAN_CTOR_DISABLE_IF(...) typename seqan::DisableIf<__VA_ARGS__>::Type * dummy = 0
/*!
* @macro EnableIfFunctionality#SEQAN_FUNC_ENABLE_IF
* @headerfile <seqan/basic.h>
* @brief Bind the visibility of a function to an expression.
*
* @signature SEQAN_FUNC_ENABLE_IF(TCondition, TResult);
*
* @param TCondition Boolean type, one of <tt>True</tt> and <tt>False</tt> or a metafunction returning such a tag
* type. If <tt>True</tt> then the function is visible, otherwise, it is not.
* @param TResult The type that the function should have as the return type in case it is enabled.
*
* This macro allows one to bind the visibility of a construtor to a boolean expression by using the <a
* href="http://en.wikipedia.org/wiki/Substitution_failure_is_not_an_error">SFINAE</a> principle for an optional argument with default value. The macro call must occur as the return type definition of the function.
*
* To avoid an unused argument warning, call <tt>ignoreUnusedVariableWarning(dummy)</tt> in the constructor's body.
*
* <b>Important:</b> The function to enable must be a function template and <tt>TCondition</tt> must include at
* least one template parameter of the function template.
*
* @section Example
*
* The following shows an example on how to properly use <tt>SEQAN_FUNC_ENABLE_IF</tt> as the last argument to the
* constructor and suppressing the unused variable warning for the dummy parameter.
*
* @snippet demos/dox/basic/enable_if.cpp enable if example function
*/
#define SEQAN_FUNC_ENABLE_IF(...) typename seqan::EnableIf<__VA_ARGS__>::Type
/*!
* @macro EnableIfFunctionality#SEQAN_FUNC_DISABLE_IF
* @headerfile <seqan/basic.h>
* @brief Bind the visibility of a function to an expression.
*
* @signature SEQAN_FUNC_DISABLE_IF(TCondition, TResult);
*
* @param TCondition Boolean type, one of <tt>True</tt> and <tt>False</tt> or a metafunction returning such a tag
* type. If <tt>False</tt> then the function is visible, otherwise, it is not.
* @param TResult The type that the function should have as the return type in case it is enabled.
*
* This macro allows one to bind the visibility of a construtor to a boolean expression by using the <a
* href="http://en.wikipedia.org/wiki/Substitution_failure_is_not_an_error">SFINAE</a> principle for an optional argument with default value. The macro call must occur as the return type definition of the function.
*
* To avoid an unused argument warning, call <tt>ignoreUnusedVariableWarning(dummy)</tt> in the constructor's body.
*
* <b>Important:</b> The function to disable must be a function template and <tt>TCondition</tt> must include at least
* one template parameter of the function template.
*
* @section Example
*
* The following shows an example on how to properly use <tt>SEQAN_FUNC_DISABLE_IF</tt> as the last argument to the
* constructor and suppressing the unused variable warning for the dummy parameter.
*
* @snippet demos/dox/basic/enable_if.cpp disable if example function
*/
#define SEQAN_FUNC_DISABLE_IF(...) typename seqan::DisableIf<__VA_ARGS__>::Type
// ============================================================================
// Functions
// ============================================================================
#endif // #ifndef SEQAN_INCLUDE_SEQAN_BASIC_METAPROGRAMMING_ENABLE_IF_H_
|