boost::enable_ifの居所について

C++11のstd::enable_ifが使えない環境だと、boost::enable_ifなしにはテンプレート関数をガンガン使っていくのは厳しい。しかし、boost::enable_ifは途中で定義されている場所が変わっている。 boost 1.65.1のドキュメントを見てみよう。 Boost Utility Library - 1.65.1 enable_ifはBoost.Coreに移したと書かれている。ついでにboost/utility/enable_if.hppにも、以下のように書かれている。

/*
 * Copyright (c) 2014 Glen Fernandes
 *
 * Distributed under the Boost Software License, Version 1.0. (See
 * accompanying file LICENSE_1_0.txt or copy at
 * http://www.boost.org/LICENSE_1_0.txt)
 */

#ifndef BOOST_UTILITY_ENABLE_IF_HPP
#define BOOST_UTILITY_ENABLE_IF_HPP

// The header file at this path is deprecated;
// use boost/core/enable_if.hpp instead.

#include <boost/core/enable_if.hpp>

#endif  

ではboost/core/enable_if.hppを使おう、と思って書いた所、別の環境に行くとコンパイルに失敗した。古いBoostが入っていたのだ。 その時はどうせ新しめのBoostにしかない機能をいくつか使っていたので野良で入れたものの、できれば古いBoostでも動くようにWorkaroundを設けたい。

Workaround自体は非常に簡単に実装できる。

#if BOOST_VERSION >= WHEN_ENABLE_IF_MOVED_TO_CORE
#include <boost/core/enable_if.hpp>
#else
#include <boost/utility/enable_if.hpp>
#endif

問題は、どのバージョンで移動したのかぱっと見わからなかったことだ。リリースノートも少し見たが、見つけられなかった(探し方が足りないのかも知れない)。

仕方がないのでcommit logを検索して2014年8月頃の話だということを突き止めた後(boostorg/utility: 492fd7f091c73494fb0062de586adc792f97c14)、boost.1.55.0, 1.56.0, 1.57.0をダウンロードしてきて確認した。 すると、boost 1.55.0ではutility/enable_if.hppに実装が書かれているのに対し、boost 1.56.0ではdeprecatedになっている。 というわけで、Workaroundができた。

#if BOOST_VERSION >= 105600
#include <boost/core/enable_if.hpp>
#else
#include <boost/utility/enable_if.hpp>
#endif