回避できないように見えるイライラするコンパイラエラーが発生します。テンプレートの特殊化と関係がありますが、何が問題なのかわかりません...
../../include/thread/lock_guard.inl:23: error: template-id 'lock_guard<>' for 'thread::lock_guard<thread::null_mutex>::lock_guard(thread::null_mutex&)' does not match any template declaration
../../include/thread/lock_guard.inl:23: error: invalid function declaration
../../include/thread/lock_guard.inl:29: error: template-id 'lock_guard<>' for 'thread::lock_guard<thread::null_mutex>::~lock_guard()' does not match any template declaration
../../include/thread/lock_guard.inl:29: error: invalid function declaration
コードは次のとおりです。
#include "thread/mutex.hpp"
namespace thread {
template <typename T>
class lock_guard
{
public:
lock_guard(T& lock);
~lock_guard();
private:
mutable T& m_lock;
mutable int m_state;
};
template <>
class lock_guard<null_mutex>
{
public:
lock_guard(null_mutex&);
~lock_guard();
};
} //namespace
#include "thread/lock_guard.inl"
------------------------------------
#include "thread/lock_guard.hpp"
namespace thread {
template <typename T>
lock_guard<T>::lock_guard(T& lock)
: m_lock(lock),
m_state(lock.lock())
{
/* do nothing */
}
template <typename T>
lock_guard<T>::~lock_guard()
{
if(0 == m_state)
{
m_lock.unlock();
}
}
template <>
lock_guard<null_mutex>::lock_guard(null_mutex&)
{
/* do nothing */
}
template <>
lock_guard<null_mutex>::~lock_guard()
{
/* do nothing */
}
} //namespace