mardi 30 décembre 2014

Why is template type deduction failing here?

Why in the following piece of code, does the template type cannot be deduced automatically from the last argument, like it does in std::condition_variable::wait ?



template< typename Predicate >
//requires Truth< Predicate >
class lock_monitor_guard
{
public:
lock_monitor_guard( std::mutex& mutex, std::condition_variable& monitor, Predicate predicate );
~lock_monitor_guard();

private:
std::unique_lock<std::mutex> lock;
std::condition_variable& monitor;
};

template< typename Predicate >
//requires Truth< Predicate >
lock_monitor_guard<Predicate>::lock_monitor_guard( std::mutex& mutex, std::condition_variable& monitor, Predicate predicate )
: lock( mutex ), monitor( monitor )
{
monitor.wait<Predicate>( lock, predicate );
}

template< typename Predicate >
//requires Truth< Predicate >
lock_monitor_guard<Predicate>::~lock_monitor_guard()
{
lock.unlock();
monitor.notify_one();
}


When I try to build a line like lock_monitor_guard guard( jobs_mutex, jobs_monitor, ([]()->bool{return true;}) );, I have an error message : use of class template 'lock_monitor_guard' requires template arguments. But why ? And why does it work with the STL std::condition_variable::wait. Thank you for any help !


Aucun commentaire:

Enregistrer un commentaire