Made add_loss_layer constructor more flexible. Now you can construct

from objects that are implicitly convertible to a loss details object
just like you can for computational layers.
This commit is contained in:
Davis King 2016-08-27 09:23:09 -04:00
parent b09ddc3ac7
commit 7c6a800bb9
2 changed files with 22 additions and 5 deletions

View File

@ -2190,11 +2190,25 @@ namespace dlib
{
}
template <typename T, typename ...U>
struct disable_forwarding_constr
{
const static bool value = std::is_constructible<LOSS_DETAILS,T>::value;
};
template <typename ...T>
struct disable_forwarding_constr<add_loss_layer<T...>>
{
const static bool value = true;
};
template <
typename ...T,
typename = typename std::enable_if<!disable_forwarding_constr<typename std::remove_reference<T>::type...>::value>::type
>
add_loss_layer(
T ...args
T&& ...args
) :
subnetwork(std::move(args)...)
subnetwork(std::forward<T>(args)...)
{
}

View File

@ -660,7 +660,7 @@ namespace dlib
);
/*!
ensures
- #loss_details() == layer_det
- #loss_details() == loss_details_type(layer_det)
- #subnet() == subnet_type(args)
!*/
@ -671,16 +671,19 @@ namespace dlib
);
/*!
ensures
- #loss_details() == layer_det
- #loss_details() == loss_details_type(layer_det)
- #subnet() == subnet_type(args)
!*/
template <typename ...T>
add_loss_layer(
T ...args
T&& ...args
);
/*!
ensures
- This version of the constructor is only called if loss_details_type can't
be constructed from the first thing in args. In this case, the args are
simply passed on to the sub layers in their entirety.
- #loss_details() == loss_details_type()
- #subnet() == subnet_type(args)
!*/