From 102881692e7078cbbc48a6cdc2a3dfb02c661b86 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EB=B0=95=EC=A2=85=ED=98=84/=EB=8F=99=EC=9E=91=EC=A0=9C?= =?utf8?q?=EC=96=B4Lab=28SR=29/Staff=20Engineer/=EC=82=BC=EC=84=B1?= =?utf8?q?=EC=A0=84=EC=9E=90?= Date: Wed, 18 Jul 2018 13:03:57 +0900 Subject: [PATCH] [nest] Add 'Domain' class (#697) This commit adds 'Domain' class which allows users to easily build dereference expression with pre-allocated domain. Signed-off-by: Jonghyun Park --- contrib/nest/include/nest/Domain.h | 38 ++++++++++++++++++++++++++++++ contrib/nest/include/nest/expr/Subscript.h | 4 ++-- contrib/nest/src/Domain.test.cpp | 25 ++++++++++++++++++++ 3 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 contrib/nest/include/nest/Domain.h create mode 100644 contrib/nest/src/Domain.test.cpp diff --git a/contrib/nest/include/nest/Domain.h b/contrib/nest/include/nest/Domain.h new file mode 100644 index 0000000..5f2ddd5 --- /dev/null +++ b/contrib/nest/include/nest/Domain.h @@ -0,0 +1,38 @@ +#ifndef __NEST_DOMAIN_H__ +#define __NEST_DOMAIN_H__ + +#include "nest/Closure.h" + +namespace nest +{ + +class Domain +{ +public: + Domain() = default; + +public: + Domain(const DomainID &id) : _id{id} + { + // DO NOTHING + } + +public: + Domain(const Domain &) = default; + +public: + template Closure operator()(Args &&... indices) + { + return Closure{_id, std::forward(indices)...}; + } + +public: + const DomainID &id(void) const { return _id; } + +private: + DomainID const _id; +}; + +} // namespace nest + +#endif // __NEST_DOMAIN_H__ diff --git a/contrib/nest/include/nest/expr/Subscript.h b/contrib/nest/include/nest/expr/Subscript.h index ba073d3..5e5a4c8 100644 --- a/contrib/nest/include/nest/expr/Subscript.h +++ b/contrib/nest/include/nest/expr/Subscript.h @@ -4,6 +4,7 @@ #include "nest/expr/Node.h" #include +#include #include @@ -15,8 +16,7 @@ namespace expr class Subscript { public: - template - Subscript(Args &&... indicies) : _indices{std::forward(indicies)...} + Subscript(std::initializer_list> indices) : _indices{indices} { // DO NOTHING } diff --git a/contrib/nest/src/Domain.test.cpp b/contrib/nest/src/Domain.test.cpp new file mode 100644 index 0000000..1b85360 --- /dev/null +++ b/contrib/nest/src/Domain.test.cpp @@ -0,0 +1,25 @@ +#include "nest/Domain.h" + +#include + +namespace +{ +namespace expr +{ +struct DummyNode final : public nest::expr::Node +{ +}; +} // namespace expr +} // namespace + +// NOTE Build failed when DOMAIN is used instead of _DOMAIN +TEST(_DOMAIN, base_usecase) +{ + nest::DomainID dom_id{0}; + nest::Domain dom{dom_id}; + + nest::Closure clo = dom(std::make_shared<::expr::DummyNode>()); + + ASSERT_EQ(clo.id(), dom_id); + ASSERT_EQ(clo.sub().rank(), 1); +} -- 2.7.4