1
0
Fork 0
mirror of https://github.com/bolero-MURAKAMI/Sprout synced 2025-08-03 12:49:50 +00:00

sprout/weed.hpp 追加

This commit is contained in:
bolero-MURAKAMI 2011-11-13 17:54:38 +09:00
parent 8103682fdb
commit ecfc2b297a
96 changed files with 5127 additions and 0 deletions

32
sprout/weed/expr/eval.hpp Normal file
View file

@ -0,0 +1,32 @@
#ifndef SPROUT_WEED_EXPR_EVAL_HPP
#define SPROUT_WEED_EXPR_EVAL_HPP
#include <sprout/config.hpp>
#include <sprout/weed/expr/make_terminal_or_expr.hpp>
#include <sprout/weed/traits/expr/terminal_or_expr_of.hpp>
namespace sprout {
namespace weed {
//
// eval
//
template<typename Expr, typename Context>
SPROUT_CONSTEXPR inline typename Context::template eval<
typename sprout::weed::traits::terminal_or_expr_of<Expr>::type
>::result_type eval(
Expr const& expr,
Context const& ctx
)
{
typedef typename Context::template eval<
typename sprout::weed::traits::terminal_or_expr_of<Expr>::type
> eval_type;
return eval_type()(
sprout::weed::make_terminal_or_expr(expr),
ctx
);
}
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_EXPR_EVAL_HPP

32
sprout/weed/expr/expr.hpp Normal file
View file

@ -0,0 +1,32 @@
#ifndef SPROUT_WEED_EXPR_EXPR_HPP
#define SPROUT_WEED_EXPR_EXPR_HPP
#include <sprout/config.hpp>
#include <sprout/tuple/tuple.hpp>
#include <sprout/utility/forward.hpp>
namespace sprout {
namespace weed {
//
// expr
//
template<typename Tag, typename... Args>
class expr {
public:
typedef Tag expr_tag;
typedef sprout::tuples::tuple<Args...> args_type;
private:
args_type args_;
public:
template<typename... As>
SPROUT_CONSTEXPR explicit expr(As&&... args)
: args_(sprout::forward<As>(args)...)
{}
SPROUT_CONSTEXPR args_type const& args() const {
return args_;
}
};
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_EXPR_EXPR_HPP

View file

@ -0,0 +1,25 @@
#ifndef SPROUT_WEED_EXPR_MAKE_EXPR_HPP
#define SPROUT_WEED_EXPR_MAKE_EXPR_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/utility/forward.hpp>
#include <sprout/weed/expr/make_terminal_or_expr.hpp>
#include <sprout/weed/traits/expr/expr_of.hpp>
namespace sprout {
namespace weed {
//
// make_expr
//
template<typename Tag, typename... Args>
SPROUT_CONSTEXPR inline typename sprout::weed::traits::expr_of<Tag, Args...>::type
make_expr(Args&&... args) {
return typename sprout::weed::traits::expr_of<Tag, Args...>::type(
sprout::weed::make_terminal_or_expr(sprout::forward<Args>(args))...
);
}
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_EXPR_MAKE_EXPR_HPP

View file

@ -0,0 +1,42 @@
#ifndef SPROUT_WEED_EXPR_MAKE_TERMINAL_HPP
#define SPROUT_WEED_EXPR_MAKE_TERMINAL_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/string.hpp>
#include <sprout/utility/forward.hpp>
#include <sprout/weed/traits/type/is_c_str.hpp>
#include <sprout/weed/traits/expr/terminal_of.hpp>
#include <sprout/weed/detail/uncvref.hpp>
namespace sprout {
namespace weed {
//
// make_terminal
//
template<typename Arg>
SPROUT_CONSTEXPR inline typename std::enable_if<
!sprout::weed::traits::is_c_str<
typename sprout::weed::detail::uncvref<Arg>::type
>::value,
typename sprout::weed::traits::terminal_of<Arg>::type
>::type make_terminal(Arg&& arg) {
return typename sprout::weed::traits::terminal_of<Arg>::type(
sprout::forward<Arg>(arg)
);
}
template<typename Arg>
SPROUT_CONSTEXPR inline typename std::enable_if<
sprout::weed::traits::is_c_str<
typename sprout::weed::detail::uncvref<Arg>::type
>::value,
typename sprout::weed::traits::terminal_of<Arg>::type
>::type make_terminal(Arg&& arg) {
return typename sprout::weed::traits::terminal_of<Arg>::type(
sprout::to_string(sprout::forward<Arg>(arg))
);
}
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_EXPR_MAKE_TERMINAL_HPP

View file

@ -0,0 +1,38 @@
#ifndef SPROUT_WEED_EXPR_MAKE_TERMINAL_OR_EXPR_HPP
#define SPROUT_WEED_EXPR_MAKE_TERMINAL_OR_EXPR_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/utility/forward.hpp>
#include <sprout/weed/expr/make_terminal.hpp>
#include <sprout/weed/traits/expr/is_expr.hpp>
#include <sprout/weed/traits/expr/terminal_or_expr_of.hpp>
#include <sprout/weed/detail/uncvref.hpp>
namespace sprout {
namespace weed {
//
// make_terminal_or_expr
//
template<typename Arg>
SPROUT_CONSTEXPR inline typename std::enable_if<
sprout::weed::traits::is_expr<
typename sprout::weed::detail::uncvref<Arg>::type
>::value,
typename sprout::weed::traits::terminal_or_expr_of<Arg>::type
>::type make_terminal_or_expr(Arg&& arg) {
return sprout::forward<Arg>(arg);
}
template<typename Arg>
SPROUT_CONSTEXPR inline typename std::enable_if<
!sprout::weed::traits::is_expr<
typename sprout::weed::detail::uncvref<Arg>::type
>::value,
typename sprout::weed::traits::terminal_or_expr_of<Arg>::type
>::type make_terminal_or_expr(Arg&& arg) {
return sprout::weed::make_terminal(sprout::forward<Arg>(arg));
}
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_EXPR_MAKE_TERMINAL_OR_EXPR_HPP

21
sprout/weed/expr/tag.hpp Normal file
View file

@ -0,0 +1,21 @@
#ifndef SPROUT_WEED_EXPR_TAG_HPP
#define SPROUT_WEED_EXPR_TAG_HPP
#include <sprout/config.hpp>
namespace sprout {
namespace weed {
namespace tag {
struct terminal {};
struct unary_plus {};
struct dereference {};
struct address_of {};
struct logical_not {};
struct shift_left {};
struct modulus {};
struct bitwise_or {};
} // namespace tag
} // namespace weed
} // namespace sprout
#endif // #ifndef SPROUT_WEED_EXPR_TAG_HPP