Skip to content

Commit

Permalink
Use template variables for functions that have explicit template para…
Browse files Browse the repository at this point in the history
…meters for issue #117
  • Loading branch information
pfultz2 committed Apr 28, 2016
1 parent 8c1a7ec commit 5c3768a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
6 changes: 5 additions & 1 deletion include/fit/arg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,16 @@ struct arg_f
};

}

#if FIT_HAS_VARIABLE_TEMPLATES
template<std::size_t N>
static constexpr auto arg_c = detail::make_args_f<std::size_t, N>{};
#else
template<std::size_t N, class... Ts>
constexpr auto arg_c(Ts&&... xs) FIT_RETURNS
(
detail::get_args<N>(FIT_FORWARD(Ts)(xs)...)
);
#endif

FIT_DECLARE_STATIC_VAR(arg, detail::arg_f);

Expand Down
6 changes: 5 additions & 1 deletion include/fit/if.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,16 @@ struct if_f
};

}

#if FIT_HAS_VARIABLE_TEMPLATES
template<bool B>
static constexpr auto if_c = detail::make_if_f<B>{};
#else
template<bool B, class F>
constexpr detail::if_adaptor<B, F> if_c(F f)
{
return detail::if_adaptor<B, F>(static_cast<F&&>(f));
}
#endif

FIT_DECLARE_STATIC_VAR(if_, detail::if_f);

Expand Down
19 changes: 18 additions & 1 deletion include/fit/result.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,29 @@ struct result_adaptor<void, F> : detail::callable_base<F>
};
};

// TODO: Make this a variable template in C++14
#if FIT_HAS_VARIABLE_TEMPLATES
namespace result_detail {
template<class Result>
struct result_f
{
template<class F>
constexpr result_adaptor<Result, F> operator()(F f) const
{
return result_adaptor<Result, F>(std::move(f));
}
};

}

template<class Result>
static constexpr auto result = result_detail::result_f<Result>{};
#else
template<class Result, class F>
constexpr result_adaptor<Result, F> result(F f)
{
return result_adaptor<Result, F>(std::move(f));
}
#endif

} // namespace fit

Expand Down

0 comments on commit 5c3768a

Please sign in to comment.