boost::iostreams::select
結局、特殊化は使わず、文字型で実装を切り替える方式にしました。
今日の成果物
#include <boost/iostreams/detail/select.hpp> namespace detail { // 汎用実装 template<class CharT, class Device> class wide_adaptor_impl; // 整数型用実装 template<std::size_t Bits, class Device> class wide_adaptor_int; } // namespace detail template<class CharT, class Device> class wide_adaptor { typedef typename boost::iostreams::select< boost::is_same<CharT,boost::int_t<32> >, detail::wide_adaptor_int<32,Device>, boost::is_same<CharT,boost::int_t<16> >, detail::wide_adaptor_int<16,Device>, boost::iostreams::else_, detail::wide_adaptor_impl<CharT,Device> >::type impl_type; // ... };
型の選択で、選択肢が多い場合は、boost::iostreams::selectが便利です。
さらに、CharTがboost::int32_tとboost::int16_tの場合を追加して、
template<class CharT, class Device> class wide_adaptor { typedef typename boost::iostreams::select< boost::is_same<CharT,boost::int_t<32> >, detail::wide_adaptor_int<32,Device>, boost::is_same<CharT,boost::int_t<16> >, detail::wide_adaptor_int<16,Device>, // これを追加したい boost::is_same<CharT,boost::int32_t>, detail::wide_adaptor_int<32,Device>, boost::is_same<CharT,boost::int16_t>, detail::wide_adaptor_int<16,Device>, boost::iostreams::else_, detail::wide_adaptor_impl<CharT,Device> >::type impl_type; // ... };
としたいところですが、32/16ビット整数型がない環境ではコンパイルエラーになります。
32ビット整数が使用できるかどうかは、
// 32ビット以上の精度を持つ最小の整数型の精度が32ビットならOK std::numeric_limits<boost::uint_least32_t>::digits == 32
で分かるはずなので、これを組み込めばいけるはずです。