Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated test code to work with c++14 (Issue #993)
- Loading branch information
Showing
7 changed files
with
61 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#ifndef STAN_MATH_PRIM_SCAL_FUNCTOR_APPLY_HPP | ||
#define STAN_MATH_PRIM_SCAL_FUNCTOR_APPLY_HPP | ||
|
||
#include <functional> | ||
#include <tuple> | ||
#include <utility> | ||
|
||
namespace stan { | ||
namespace math { | ||
/* | ||
* Invoke the functor f with arguments given in t and indexed in the index | ||
* sequence I | ||
* | ||
* @tparam F Type of functor | ||
* @tparam Tuple Type of tuple containing arguments | ||
* @tparam I Index sequence going from 0 to std::tuple_size<T>::value - 1 | ||
* inclusive | ||
* @param f functor callable | ||
* @param t tuple of arguments | ||
* @param i placeholder variable for index sequence | ||
*/ | ||
template <class F, class Tuple, std::size_t... I> | ||
constexpr decltype(auto) apply_impl(F&& f, Tuple&& t, | ||
std::index_sequence<I...> i) { | ||
return f(std::forward<decltype(std::get<I>(t))>(std::get<I>(t))...); | ||
} | ||
|
||
/* | ||
* Call the functor f with the tuple of arguments t, like: | ||
* | ||
* f(std::get<0>(t), std::get<1>(t), ...) | ||
* | ||
* TODO: replace this with implementation in C++ std when C++17 is available | ||
* | ||
* @tparam F Type of functor | ||
* @tparam Tuple Type of tuple containing arguments | ||
* @param f functor callable | ||
* @param t tuple of arguments | ||
*/ | ||
template <class F, class Tuple> | ||
constexpr decltype(auto) apply(F&& f, Tuple&& t) { | ||
return apply_impl(std::forward<F>(f), std::forward<Tuple>(t), | ||
std::make_index_sequence< | ||
std::tuple_size<std::remove_reference_t<Tuple>>{}>{}); | ||
} | ||
|
||
} // namespace math | ||
} // namespace stan | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters