From c50fa91d80d085544789f05c9e6ee35a5aeac124 Mon Sep 17 00:00:00 2001 From: massimo morara Date: Fri, 4 May 2018 19:06:11 +0200 Subject: [PATCH] version 0.2.1 --- LICENSE | 2 +- changelog.txt | 8 ++ examples/Makefile | 4 +- examples/yarg-example-001.cpp | 2 +- examples/yarg-example-002.cpp | 2 +- examples/yarg-example-003.cpp | 2 +- src/yarg/yarg.h | 122 +++++++++-------------------- test/Makefile | 4 +- test/test-base-11,14,gcc,clang.cpp | 2 +- test/test_yarg-11,14,gcc,clang.cpp | 2 +- 10 files changed, 53 insertions(+), 97 deletions(-) diff --git a/LICENSE b/LICENSE index 30a67fb..1025c66 100644 --- a/LICENSE +++ b/LICENSE @@ -1,7 +1,7 @@ MIT License -Copyright (c) 2016, 2017 massimo morara +Copyright (c) 2016-2018 massimo morara Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/changelog.txt b/changelog.txt index 656163b..a81359c 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,4 +1,12 @@ +0.2.1 - 2017.05.04 +- correction in Makefile's "clean" targets (to work also with shell sh) +- substituted ugly macros in yarg.h with ordered overload resolution for + insertion of elements and size detection in containers (no behaviour + changes for yarg class) +- minor corrections and minor (mainly aesthetic) changes + + 0.2.0 - 2017.06.23 - usage() method added with some help support methods (setUsageArgsDescr(), diff --git a/examples/Makefile b/examples/Makefile index 1720322..ce2cbe1 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -1,5 +1,5 @@ -# Copyright (c) 2016, 2017 massimo morara +# Copyright (c) 2016-2018 massimo morara # Distributed under the Mit License # See accompanying file LICENSE @@ -15,7 +15,7 @@ YARGH = ../src/yarg/yarg.h all: $(EXES) clean: - - rm $(EXES) $(EXES:%=%.o) >& /dev/null + - rm $(EXES) $(EXES:%=%.o) > /dev/null 2>&1 yargDependent = *.o diff --git a/examples/yarg-example-001.cpp b/examples/yarg-example-001.cpp index 85c3430..e0fb267 100644 --- a/examples/yarg-example-001.cpp +++ b/examples/yarg-example-001.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2016, 2017 massimo morara +// Copyright (c) 2016-2018 massimo morara // Distributed under the Mit License // See accompanying file LICENSE diff --git a/examples/yarg-example-002.cpp b/examples/yarg-example-002.cpp index 94faab4..6df47b5 100644 --- a/examples/yarg-example-002.cpp +++ b/examples/yarg-example-002.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2016, 2017 massimo morara +// Copyright (c) 2016-2018 massimo morara // Distributed under the Mit License // See accompanying file LICENSE diff --git a/examples/yarg-example-003.cpp b/examples/yarg-example-003.cpp index ffb5819..a801ec8 100644 --- a/examples/yarg-example-003.cpp +++ b/examples/yarg-example-003.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2016, 2017 massimo morara +// Copyright (c) 2016-2018 massimo morara // Distributed under the Mit License // See accompanying file LICENSE.txt diff --git a/src/yarg/yarg.h b/src/yarg/yarg.h index 6b1404c..1542aa5 100644 --- a/src/yarg/yarg.h +++ b/src/yarg/yarg.h @@ -1,7 +1,7 @@ #if 0 -Copyright (c) 2016, 2017 massimo morara +Copyright (c) 2016-2018 massimo morara Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -49,7 +49,7 @@ namespace yarg // see https://github.com/massimomorara/yarg for latest version #define Yarg_Version_Major 0 #define Yarg_Version_Minor 2 - #define Yarg_Version_Patch 0 + #define Yarg_Version_Patch 1 template X extractVal (std::string const & str) @@ -134,69 +134,6 @@ namespace yarg { setBoolT(b); } }; - struct emptyStruct - { }; - - template - struct funcType; - - template - struct funcType - { using type - = typename std::conditional::type>::type; }; - - template <> - struct funcType<> - { using type = emptyStruct; }; - -#define methodCheck_1(meth) \ - \ - struct helpMeth_1_##meth { }; \ - \ - template \ - struct isWithMethod_1_##meth \ - { \ - template \ - static decltype(std::declval().meth(std::declval())) func (U*); \ - \ - template \ - static emptyStruct func (...); \ - \ - static const bool result \ - = ! std::is_same(nullptr))>::value; \ - \ - using type = helpMeth_1_##meth; \ - } - -#define methodCheck_0(meth) \ - \ - struct helpMeth_0_##meth { }; \ - \ - template \ - struct isWithMethod_0_##meth \ - { \ - template \ - static decltype(std::declval().meth()) func (U*); \ - \ - template \ - static emptyStruct func (...); \ - \ - static const bool result \ - = ! std::is_same(nullptr))>::value; \ - \ - using type = helpMeth_0_##meth; \ - } - - methodCheck_1(insert); - methodCheck_1(push); - methodCheck_1(push_back); - methodCheck_1(push_front); - - methodCheck_0(size); - template class optC; @@ -206,40 +143,50 @@ namespace yarg { private: - using addModeType2 = typename funcType< - isWithMethod_1_push_back, X>, - isWithMethod_1_insert, X>, - isWithMethod_1_push, X>, - isWithMethod_1_push_front, X>>::type; + using cType = C; - using sizeModeType = typename funcType< - isWithMethod_0_size>>::type; + // choiche level: see https://blog.rmf.io/cxx11/overload-ranking + using choiche_0 = int &&; + using choiche_1 = int const &&; + using choiche_2 = int const volatile &&; + using choiche_3 = int const &; + using choiche_4 = long &&; + using choiche_5 = long const &&; + using choiche_6 = long const volatile &&; + using choiche_7 = long const &; - static constexpr addModeType2 addMode { }; - static constexpr sizeModeType sizeMode { }; + cType val { }; - C val { }; - - void addVal (std::string const & s, helpMeth_1_push_back const) + template + auto addValHelper (std::string const & s, choiche_0) + -> decltype((void)std::declval().push_back(extractVal(s))) { val.push_back(extractVal(s)); } - void addVal (std::string const & s, helpMeth_1_push const) - { val.push(extractVal(s)); } - - void addVal (std::string const & s, helpMeth_1_insert const) + template + auto addValHelper (std::string const & s, choiche_1) + -> decltype((void)std::declval().insert(extractVal(s))) { val.insert(extractVal(s)); } - void addVal (std::string const & s, helpMeth_1_push_front const) + template + auto addValHelper (std::string const & s, choiche_2) + -> decltype((void)std::declval().push(extractVal(s))) + { val.push(extractVal(s)); } + + template + auto addValHelper (std::string const & s, choiche_3) + -> decltype((void)std::declval().push_front(extractVal(s))) { val.push_front(extractVal(s)); } - void addVal (std::string const & s, emptyStruct const) + void addValHelper (std::string const & s, ...) { throw std::runtime_error { "optC<>::addVal without mode for" " value [" + s + "]" }; } - std::size_t getDim (helpMeth_0_size const) const + template + auto getDimHelper (choiche_0) const + -> decltype( std::declval().size(), std::size_t{} ) { return val.size(); } - std::size_t getDim (emptyStruct const) const + std::size_t getDimHelper (...) const { return std::distance(val.cbegin(), val.cend()); } public: @@ -257,10 +204,10 @@ namespace yarg { return val; } std::size_t getDim () const final - { return getDim(sizeMode); } + { return getDimHelper(0); } void setVal (std::string const & s) final - { addVal(s, addMode); } + { addValHelper(s, 0); } void setBool (bool) final { } @@ -275,6 +222,7 @@ namespace yarg std::size_t pos { 0 }; public: + optC () { } diff --git a/test/Makefile b/test/Makefile index df3b20e..1a1a369 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,5 +1,5 @@ -# Copyright (c) 2016, 2017 massimo morara +# Copyright (c) 2016-2018 massimo morara # Distributed under the Mit License # See accompanying file LICENSE @@ -33,7 +33,7 @@ all: $(TESTS_11_GCC) $(TESTS_11_CLANG) $(TESTS_14_GCC) $(TESTS_14_CLANG) clean: - rm $(TESTS_11_GCC) $(TESTS_11_GCC:%=%.o) $(TESTS_11_CLANG) \ $(TESTS_11_CLANG:%=%.o) $(TESTS_14_GCC) $(TESTS_14_GCC:%=%.o) \ - $(TESTS_14_CLANG) $(TESTS_14_CLANG:%=%.o) >& /dev/null + $(TESTS_14_CLANG) $(TESTS_14_CLANG:%=%.o) > /dev/null 2>&1 $(TESTS_11_GCC):%: %.o test-base-11-gcc.o $(COMMON_DEPS) $(CPP_GCC) -o $@ $(LDFLAGS_11_GCC) test-base-11-gcc.o $< diff --git a/test/test-base-11,14,gcc,clang.cpp b/test/test-base-11,14,gcc,clang.cpp index 0ce3e63..7d185ea 100644 --- a/test/test-base-11,14,gcc,clang.cpp +++ b/test/test-base-11,14,gcc,clang.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2016, 2017 massimo morara +// Copyright (c) 2016-2018 massimo morara // Distributed under the Mit License // See accompanying file LICENSE diff --git a/test/test_yarg-11,14,gcc,clang.cpp b/test/test_yarg-11,14,gcc,clang.cpp index 73f5a31..f4a14d7 100644 --- a/test/test_yarg-11,14,gcc,clang.cpp +++ b/test/test_yarg-11,14,gcc,clang.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2016, 2017 massimo morara +// Copyright (c) 2016-2018 massimo morara // Distributed under the Mit License // See accompanying file LICENSE