00001 // -*- C++ -*- 00002 00003 //============================================================================= 00004 /** 00005 * @file If_Then_Else.h 00006 * 00007 * @c ACE::If_Then_Else traits template based on the @c IfThenElse 00008 * template described in the book "C++ Templates" by Vandevoorde and 00009 * Josuttis. 00010 * 00011 * $Id: If_Then_Else.h 69669 2005-11-27 12:11:35Z ossama $ 00012 * 00013 * @author Ossama Othman <ossama@dre.vanderbilt.edu> 00014 */ 00015 //============================================================================= 00016 00017 #ifndef ACE_IF_THEN_ELSE_H 00018 #define ACE_IF_THEN_ELSE_H 00019 00020 #include "ace/config-lite.h" 00021 00022 ACE_BEGIN_VERSIONED_NAMESPACE_DECL 00023 00024 namespace ACE 00025 { 00026 00027 /** 00028 * @struct If_Then_Else 00029 * 00030 * @brief Compile-time selection of type based on a boolean value. 00031 * 00032 * This primary template selects the second or third argument based 00033 * on the value of the boolean first argument. 00034 * 00035 * Usage example: 00036 * 00037 * \code 00038 * 00039 * template <typename T> 00040 * class Foo 00041 * { 00042 * public: 00043 * // Set "TheType" to be the larger of "T" and "int". 00044 * typedef typename If_Then_Else<(sizeof (T) > sizeof (int)), 00045 * T, 00046 * int>::result_type TheType; 00047 * }; 00048 * 00049 * \endcode 00050 * 00051 * @note This merely a forward declaration since we really only care 00052 * about the partial specializations below. 00053 */ 00054 template <bool C, typename Ta, typename Tb> 00055 struct If_Then_Else; 00056 00057 /** 00058 * @struct If_Then_Else 00059 * 00060 * @brief Select of type @a Ta if boolean value is @c true. 00061 * 00062 * This partial specialization selects the type @a Ta if the boolean 00063 * first argument is @c true. 00064 */ 00065 template <typename Ta, typename Tb> 00066 struct If_Then_Else<true, Ta, Tb> 00067 { 00068 typedef Ta result_type; 00069 }; 00070 00071 /** 00072 * @struct If_Then_Else 00073 * 00074 * @brief Select of type @a Tb if boolean value is @c false. 00075 * 00076 * This partial specialization selects the type @a Tb if the boolean 00077 * first argument is @c false. 00078 */ 00079 template <typename Ta, typename Tb> 00080 struct If_Then_Else<false, Ta, Tb> 00081 { 00082 typedef Tb result_type; 00083 }; 00084 00085 } 00086 00087 ACE_END_VERSIONED_NAMESPACE_DECL 00088 00089 #endif /* ACE_IF_THEN_ELSE_H */