From b6051f157b05139459aa907cae1c93c73d906b02 Mon Sep 17 00:00:00 2001 From: RanolP Date: Mon, 9 Mar 2020 20:19:19 +0900 Subject: [PATCH] =?UTF-8?q?Creepers=20are=20not=20my=20enemy.=20I=20can=20?= =?UTF-8?q?boom=20better=20than=20them.=20=F0=9F=92=A5=F0=9F=92=A5?= =?UTF-8?q?=F0=9F=92=A5=F0=9F=92=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/settings.json | 40 +++++++++++++++++++++++++++++- examples/CMakeLists.txt | 5 ++-- examples/Counter.cpp | 40 +++++++++++++++++++++++++----- include/spaic-css/detail/CSS.hpp | 2 +- include/spaic/Component.hpp | 2 +- include/spaic/Message.hpp | 2 +- include/spaic/Property.hpp | 2 ++ include/spaic/VNode.hpp | 17 ++++++++++++- include/spaic/detail/Component.hpp | 6 +++-- src/spaic-css/CMakeLists.txt | 5 ++-- src/spaic-dom/CMakeLists.txt | 5 ++-- src/spaic/CMakeLists.txt | 5 ++-- 12 files changed, 110 insertions(+), 21 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 16d6bab..b9a788b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -14,6 +14,44 @@ "array": "cpp", "tuple": "cpp", "utility": "cpp", - "functional": "cpp" + "functional": "cpp", + "istream": "cpp", + "variant": "cpp", + "atomic": "cpp", + "bit": "cpp", + "cctype": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "unordered_map": "cpp", + "vector": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "random": "cpp", + "string": "cpp", + "string_view": "cpp", + "fstream": "cpp", + "initializer_list": "cpp", + "iosfwd": "cpp", + "limits": "cpp", + "new": "cpp", + "ostream": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "cinttypes": "cpp", + "typeinfo": "cpp" } } diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index eff3c85..76c000c 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,10 +1,11 @@ -cmake_minimum_required(VERSION 3.8.0) +cmake_minimum_required(VERSION 3.12.0) project(SpaicExample) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) +add_compile_options(-fconcepts) include_directories("../include/") file(GLOB_RECURSE SOURCE_LIST "./*.cpp") diff --git a/examples/Counter.cpp b/examples/Counter.cpp index af8022c..017214b 100644 --- a/examples/Counter.cpp +++ b/examples/Counter.cpp @@ -1,4 +1,5 @@ #include +#include #include #include @@ -42,13 +43,40 @@ VNode render() return 0; } -auto counter = create_component(props::counter::all, state::counter::all, update, render); - int main() { - using namespace props::counter; - auto wtf_is_this_style = css( - width = 10.0_px); - counter(is_dark_theme = true)("Hello, world!"); + std::cout << "안녕 세계는 개뿔이" << std::endl; + try + { + using namespace props::counter; + auto wtf_is_this_style = css( + width = 10.0_px); + auto counter = create_component(props::counter::all, state::counter::all, update, render); + + counter(is_dark_theme = true)("Hello, world!"); + } + catch (const char *e) + { + std::cout << e << std::endl; + } return EXIT_SUCCESS; } + +// fucking test +void test(VNode node) {} + +struct Incompatible +{ + int i; +}; + +void test() +{ + using namespace props::counter; + test("STR"); + test(true); + std::vector wtf; + wtf.push_back("STR"); + test(wtf); + // test(Incompatible{3}); +} \ No newline at end of file diff --git a/include/spaic-css/detail/CSS.hpp b/include/spaic-css/detail/CSS.hpp index 19efa0f..b0693fe 100644 --- a/include/spaic-css/detail/CSS.hpp +++ b/include/spaic-css/detail/CSS.hpp @@ -7,6 +7,6 @@ namespace spaic::css template spaic::css::Stylesheet css(T... params) { - throw "TODO"; + throw "TODO: css(params)"; } } // namespace spaic::css diff --git a/include/spaic/Component.hpp b/include/spaic/Component.hpp index 62e42b3..a194534 100644 --- a/include/spaic/Component.hpp +++ b/include/spaic/Component.hpp @@ -14,7 +14,7 @@ using Render = std::function; class ComponentBody { public: - spaic::vnode::VNode operator()(spaic::vnode::VNode children...) noexcept; + spaic::vnode::VNode operator()(spaic::vnode::VNode children...); // noexcept; }; template class Component diff --git a/include/spaic/Message.hpp b/include/spaic/Message.hpp index 7a5f38c..d025bc0 100644 --- a/include/spaic/Message.hpp +++ b/include/spaic/Message.hpp @@ -13,7 +13,7 @@ class Message operator bool(); template - typename std::tuple_element>::type get(); + std::tuple_element_t> get(); }; } // namespace spaic::msg diff --git a/include/spaic/Property.hpp b/include/spaic/Property.hpp index 109b4ae..247ed7c 100644 --- a/include/spaic/Property.hpp +++ b/include/spaic/Property.hpp @@ -14,6 +14,8 @@ class Property public: virtual AssignedProperty operator=(I &&value) noexcept {}; + + O &operator*() noexcept; }; template diff --git a/include/spaic/VNode.hpp b/include/spaic/VNode.hpp index f286aa4..506f62d 100644 --- a/include/spaic/VNode.hpp +++ b/include/spaic/VNode.hpp @@ -7,7 +7,7 @@ namespace spaic::vnode { // TODO: Array of VNode should be VNode. -using VNode = std::variant< +using VNodeBase = std::variant< std::string, std::nullptr_t, bool, @@ -28,4 +28,19 @@ using VNode = std::variant< float, double, long double>; + +class VNode final +{ +private: + // I prefer `_value` + // wtf is that noexcept(noexcept()) + std::variant> _value; + +public: + template + requires std::is_convertible_v, VNodeBase> || + std::is_convertible_v, std::vector> + VNode(T &&v) noexcept(noexcept(std::is_constructible_v(v))>)) + : _value(std::forward(v)) {} +}; } // namespace spaic::vnode diff --git a/include/spaic/detail/Component.hpp b/include/spaic/detail/Component.hpp index db41b7b..466c89a 100644 --- a/include/spaic/detail/Component.hpp +++ b/include/spaic/detail/Component.hpp @@ -1,3 +1,4 @@ + #pragma once #include @@ -8,7 +9,7 @@ namespace spaic::comp { -spaic::vnode::VNode ComponentBody::operator()(spaic::vnode::VNode children...) noexcept +spaic::vnode::VNode ComponentBody::operator()(spaic::vnode::VNode children...) // noexcept { throw "TODO: ComponentBody::operator()(children)"; } @@ -17,7 +18,8 @@ template template ComponentBody Component::operator()(T... args) noexcept { - throw "TODO: Component::operator()(args)"; + // TODO: Component::operator()(args) + return ComponentBody(); } template Component create_component(Props props, StateSet state, Update update, Render render) diff --git a/src/spaic-css/CMakeLists.txt b/src/spaic-css/CMakeLists.txt index 7a7dbd1..7244940 100644 --- a/src/spaic-css/CMakeLists.txt +++ b/src/spaic-css/CMakeLists.txt @@ -1,10 +1,11 @@ -cmake_minimum_required(VERSION 3.8.0) +cmake_minimum_required(VERSION 3.12.0) project(SpaicCSS) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) +add_compile_options(-fconcepts) include_directories("../../include/") file(GLOB_RECURSE SOURCE_LIST "./*.cpp") diff --git a/src/spaic-dom/CMakeLists.txt b/src/spaic-dom/CMakeLists.txt index f6069c3..55d585d 100644 --- a/src/spaic-dom/CMakeLists.txt +++ b/src/spaic-dom/CMakeLists.txt @@ -1,10 +1,11 @@ -cmake_minimum_required(VERSION 3.8.0) +cmake_minimum_required(VERSION 3.12.0) project(SpaicDOM) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) +add_compile_options(-fconcepts) include_directories("../../include/") file(GLOB_RECURSE SOURCE_LIST "./*.cpp") diff --git a/src/spaic/CMakeLists.txt b/src/spaic/CMakeLists.txt index 69dac14..6dbcee3 100644 --- a/src/spaic/CMakeLists.txt +++ b/src/spaic/CMakeLists.txt @@ -1,10 +1,11 @@ -cmake_minimum_required(VERSION 3.8.0) +cmake_minimum_required(VERSION 3.12.0) project(Spaic) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) +add_compile_options(-fconcepts) include_directories("../../include/") file(GLOB_RECURSE SOURCE_LIST "./*.cpp")