├── shand ├── old │ ├── shand.chm │ ├── depend │ │ ├── file.hpp │ │ ├── to_string.hpp │ │ ├── cstring_format.h │ │ ├── singleton_holder.hpp │ │ ├── message_box.h │ │ ├── date_time.h │ │ ├── tray_icon.hpp │ │ └── elapsed_time.hpp │ ├── mpl │ │ ├── to_string.hpp │ │ ├── identity.hpp │ │ ├── if.hpp │ │ └── eval_if.hpp │ ├── assign │ │ ├── list_inserter.hpp │ │ ├── std.hpp │ │ ├── deque.hpp │ │ ├── list.hpp │ │ ├── queue.hpp │ │ ├── stack.hpp │ │ ├── vector.hpp │ │ ├── set.hpp │ │ └── map.hpp │ ├── null_ptr.hpp │ ├── static_assert.hpp │ ├── io.hpp │ ├── switch.hpp │ ├── log.hpp │ ├── enable_if.hpp │ ├── lexical_cast.hpp │ ├── istream_line.hpp │ ├── shared_array.hpp │ ├── 作りかけ │ │ └── type_list.h │ └── counting.hpp ├── boost_thread_header_only.hpp ├── io_adaptor │ ├── adapted │ │ ├── std_container.hpp │ │ ├── std_list.hpp │ │ ├── std_deque.hpp │ │ └── std_vector.hpp │ ├── example.cpp │ ├── traits.hpp │ └── io.hpp ├── to_weak.hpp ├── as_range.hpp ├── spirit_qi │ └── valid_check.hpp ├── optional_algorithm │ ├── map_find.hpp │ ├── find_if.hpp │ ├── max_element.hpp │ └── min_element.hpp ├── strong_typedef │ ├── tagged_int_io.hpp │ ├── tagged_float_io.hpp │ ├── tagged_float.hpp │ └── tagged_int.hpp ├── algorithm │ └── adjacent_for_each.hpp ├── fusion │ ├── adjacency_for_each.hpp │ ├── adjacency_transform.hpp │ └── copy.hpp ├── demangle_typename.hpp ├── encoding_string │ ├── system_string.hpp │ ├── codeunit_iterator.hpp │ ├── normalizer.hpp │ └── utf32_string.hpp ├── lambda_return.hpp ├── strict_types │ ├── bool.hpp │ ├── real.hpp │ └── integer.hpp ├── type_traits │ └── is_callable.hpp ├── duration.hpp ├── callback_promise.hpp ├── round.hpp ├── concurrent │ └── queue.hpp ├── eigen_la.hpp ├── file_mapping_container.hpp ├── special_value.hpp ├── static_map.hpp ├── errorable.hpp ├── immutable_vector.hpp ├── encoding_string.hpp ├── match.hpp ├── angle.hpp ├── graph │ └── euler_path.hpp └── graph_literal.hpp └── libs ├── date_time └── test │ └── date_time.cpp ├── graph_literal └── example │ ├── test.png │ ├── test.dot │ └── graph_literal.cpp ├── encoding_string ├── doc │ ├── reference.md │ ├── build.md │ ├── reference │ │ ├── encoding_string │ │ │ ├── encoding_string │ │ │ │ ├── codeunit_size.md │ │ │ │ ├── empty.md │ │ │ │ ├── c_str.md │ │ │ │ ├── codeunit_at.md │ │ │ │ ├── raw_str.md │ │ │ │ ├── end.md │ │ │ │ ├── begin.md │ │ │ │ └── codeunit_substr.md │ │ │ └── encoding_string.md │ │ └── encoding_string.md │ ├── basic_usage.md │ └── future_plan.md ├── example.cpp ├── README.md ├── encode_test.cpp ├── utf8_test.cpp └── utf32_test.cpp ├── algorithm ├── example │ └── adjacent_for_each.cpp └── test │ └── adjacent_for_each.cpp ├── angle └── example │ └── angle_example.cpp ├── immutable_vector ├── example │ └── example.cpp └── test │ └── test.cpp ├── as_range └── example.cpp ├── strict_types ├── strict_integer_example.cpp ├── strict_bool_example.cpp └── strict_real_example.cpp ├── special_value ├── example │ └── example.cpp └── test │ └── test.cpp ├── optional_algorithm └── test │ ├── map_find.cpp │ ├── find_if.cpp │ ├── max_element.cpp │ └── min_element.cpp ├── fusion └── example │ └── adjacency_for_each.cpp ├── strong_typedef ├── test_hash.cpp ├── tagged_int_example.cpp ├── tagged_float_example.cpp ├── test_tagged_float.cpp └── test_tagged_int.cpp ├── match ├── example │ └── match.cpp └── test │ └── match.cpp ├── trace_value └── example.cpp ├── spirit_qi └── example │ └── valid_check.cpp ├── random └── random_device_example.cpp ├── round └── test.cpp ├── static_map └── test │ └── test.cpp ├── eigen_la └── example │ └── angle_example.cpp ├── concurrent └── example │ └── queue.cpp ├── callback_promise ├── io_service.cpp └── test.cpp ├── graph └── euler_path │ ├── santa_house.cpp │ ├── test_has_euler_path.cpp │ └── test_euler_path.cpp └── errorable └── example.cpp /shand/old/shand.chm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faithandbrave/Shand/HEAD/shand/old/shand.chm -------------------------------------------------------------------------------- /shand/old/depend/file.hpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faithandbrave/Shand/HEAD/shand/old/depend/file.hpp -------------------------------------------------------------------------------- /shand/old/mpl/to_string.hpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faithandbrave/Shand/HEAD/shand/old/mpl/to_string.hpp -------------------------------------------------------------------------------- /libs/date_time/test/date_time.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faithandbrave/Shand/HEAD/libs/date_time/test/date_time.cpp -------------------------------------------------------------------------------- /shand/boost_thread_header_only.hpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faithandbrave/Shand/HEAD/shand/boost_thread_header_only.hpp -------------------------------------------------------------------------------- /shand/old/assign/list_inserter.hpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faithandbrave/Shand/HEAD/shand/old/assign/list_inserter.hpp -------------------------------------------------------------------------------- /libs/graph_literal/example/test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faithandbrave/Shand/HEAD/libs/graph_literal/example/test.png -------------------------------------------------------------------------------- /libs/encoding_string/doc/reference.md: -------------------------------------------------------------------------------- 1 | # リファレンス 2 | 3 | - [``](./reference/encoding_string.md) 4 | 5 | -------------------------------------------------------------------------------- /libs/graph_literal/example/test.dot: -------------------------------------------------------------------------------- 1 | digraph G { 2 | 0[label=A]; 3 | 1[label=B]; 4 | 2[label=C]; 5 | 3[label=D]; 6 | 0->1 ; 7 | 0->2 ; 8 | 2->3 ; -------------------------------------------------------------------------------- /shand/io_adaptor/adapted/std_container.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_IO_ADAPTOR_ADAPTED_STD_CONTAINER_INCLUDE 2 | #define SHAND_IO_ADAPTOR_ADAPTED_STD_CONTAINER_INCLUDE 3 | 4 | #include "./std_vector.hpp" 5 | #include "./std_list.hpp" 6 | #include "./std_deque.hpp" 7 | 8 | #endif // SHAND_IO_ADAPTOR_ADAPTED_STD_CONTAINER_INCLUDE 9 | 10 | 11 | -------------------------------------------------------------------------------- /shand/io_adaptor/example.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include 6 | 7 | int main() 8 | { 9 | std::vector > v = {{1, 2}, {3, 4}, {5, 6}}; 10 | 11 | using namespace shand::io_adaptors::operators; 12 | std::cout << v << std::endl; 13 | } 14 | 15 | 16 | -------------------------------------------------------------------------------- /shand/old/null_ptr.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_NULL_POINTER_INCLUDE 2 | #define SHAND_NULL_POINTER_INCLUDE 3 | 4 | // Copyright Akira Takahashi 2007 5 | // Use, modification and distribution is subject to the Boost Software License, 6 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | namespace shand { 10 | 11 | template 12 | inline Type* null_ptr() 13 | { 14 | return 0; 15 | } 16 | 17 | } // namespace shand 18 | 19 | #endif // SHAND_NULL_POINTER_INCLUDE 20 | 21 | -------------------------------------------------------------------------------- /libs/encoding_string/doc/build.md: -------------------------------------------------------------------------------- 1 | # ビルド方法 2 | Shandライブラリおよび`encoding_string`クラスはヘッダオンリーで実装している。 3 | 4 | ここでは、`encoding_string`クラスが依存しているライブラリであるICUのビルド方法を、例として示す。 5 | 6 | ## Mac OS X 7 | 8 | MacPortsでインストールする。以下のコマンドを実行することで、`/opt/local/lib/`ディレクトリ以下に、ICUの静的および動的ライブラリがインストールされ、ヘッダファイルへのパスも自動的に通る。 9 | 10 | ``` 11 | sudo port install icu 12 | ``` 13 | 14 | 15 | `encoding_string`クラスを使用する場合、プログラムのコンパイルオプションとして、`libicuuc.a`および`libicudata.a`をリンクする。以下は、g++でのコンパイル例: 16 | 17 | ``` 18 | g++-mp-4.8 main.cpp -std=c++11 -L/opt/local/lib -licuuc -licudata 19 | ``` 20 | 21 | -------------------------------------------------------------------------------- /shand/old/mpl/identity.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_MPL_IDENTITY_INCLUDE 2 | #define SHAND_MPL_IDENTITY_INCLUDE 3 | 4 | // Copyright Aleksey Gurtovoy 2000-2004 5 | // Copyright Akira Takahashi 2007 6 | // Use, modification and distribution is subject to the Boost Software License, 7 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 8 | // http://www.boost.org/LICENSE_1_0.txt) 9 | 10 | 11 | namespace shand { namespace mpl { 12 | 13 | template 14 | struct identity { 15 | typedef Type type; 16 | }; 17 | 18 | }} // namespace shand::mpl 19 | 20 | #endif // SHAND_MPL_IDENTITY_INCLUDE 21 | 22 | -------------------------------------------------------------------------------- /libs/encoding_string/doc/reference/encoding_string/encoding_string/codeunit_size.md: -------------------------------------------------------------------------------- 1 | # codeunit_size 2 | ```cpp 3 | std::size_t codeunit_size() const; 4 | ``` 5 | 6 | ## 概要 7 | コードユニット数を取得する。 8 | 9 | 10 | ## 戻り値 11 | 文字列に含まれているコードユニット数を取得する。 12 | 13 | 14 | ## 計算量 15 | O(N) 16 | 17 | 18 | ## 例 19 | ```cpp 20 | #include 21 | #include 22 | 23 | int main() 24 | { 25 | using namespace shand; 26 | encoding_string s = u8"あいうえお"; 27 | 28 | std::cout << s.codeunit_size() << std::endl; 29 | } 30 | ``` 31 | 32 | ## 出力 33 | ``` 34 | 5 35 | ``` 36 | 37 | 38 | -------------------------------------------------------------------------------- /shand/old/assign/std.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_ASSIGN_STANDARD_INCLUDE 2 | #define SHAND_ASSIGN_STANDARD_INCLUDE 3 | 4 | // Copyright Thorsten Ottosen 2003-2004. 5 | // Copyright Akira Takahashi 2007 6 | // Use, modification and distribution is subject to the Boost Software License, 7 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 8 | // http://www.boost.org/LICENSE_1_0.txt) 9 | 10 | 11 | #include "vector.hpp" 12 | #include "list.hpp" 13 | #include "stack.hpp" 14 | #include "queue.hpp" 15 | #include "deque.hpp" 16 | #include "map.hpp" 17 | #include "set.hpp" 18 | 19 | #endif // SHAND_ASSIGN_STANDARD_INCLUDE 20 | 21 | -------------------------------------------------------------------------------- /libs/encoding_string/doc/reference/encoding_string/encoding_string/empty.md: -------------------------------------------------------------------------------- 1 | # empty 2 | ```cpp 3 | bool empty() const; 4 | ``` 5 | 6 | ## 概要 7 | 文字列が空かを判定する。 8 | 9 | 10 | ## 戻り値 11 | 文字列が空の場合は`true`、そうでなければ`false`を返す。 12 | 13 | 14 | ## 計算量 15 | O(1) 16 | 17 | 18 | ## 例 19 | ```cpp 20 | #include 21 | #include 22 | 23 | int main() 24 | { 25 | using namespace shand; 26 | 27 | encoding_string s1; 28 | assert(s1.empty()); 29 | 30 | encoding_string s2 = "hello"; 31 | assert(!s2.empty()); 32 | } 33 | ``` 34 | 35 | ## 出力 36 | ``` 37 | ``` 38 | 39 | 40 | -------------------------------------------------------------------------------- /libs/algorithm/example/adjacent_for_each.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Akira Takahashi 2015 2 | // Use, modification and distribution is subject to the Boost Software License, 3 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | int main() 11 | { 12 | const std::vector v = {1, 2, 3}; 13 | 14 | shand::adjacent_for_each(v, [](int a, int b) { 15 | std::cout << a << " : " << b << std::endl; 16 | }); 17 | } 18 | 19 | /* 20 | output: 21 | 1 : 2 22 | 2 : 3 23 | */ 24 | -------------------------------------------------------------------------------- /shand/io_adaptor/traits.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_IO_ADAPTOR_TRAITS_INCLUDE 2 | #define SHAND_IO_ADAPTOR_TRAITS_INCLUDE 3 | 4 | #include 5 | #include 6 | 7 | namespace shand { namespace io_adaptors { 8 | 9 | template 10 | struct is_adapted : boost::mpl::false_ {}; 11 | 12 | struct none_tag {}; 13 | struct range_tag {}; 14 | struct fusion_tag {}; 15 | 16 | template 17 | struct tag_of : boost::mpl::identity {}; 18 | 19 | }} // namespace shand::io_adaptors 20 | 21 | #endif // SHAND_IO_ADAPTOR_TRAITS_INCLUDE 22 | 23 | -------------------------------------------------------------------------------- /shand/to_weak.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_TO_WEAK_INCLUDE 2 | #define SHAND_TO_WEAK_INCLUDE 3 | 4 | // Copyright Akira Takahashi 2015 5 | // Use, modification and distribution is subject to the Boost Software License, 6 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | #include 11 | 12 | namespace shand { 13 | 14 | // for Initialized lambda captures of C++14 15 | template 16 | std::weak_ptr to_weak(const std::shared_ptr& sp) BOOST_NOEXCEPT 17 | { 18 | return sp; 19 | } 20 | 21 | } // namespace shand 22 | 23 | #endif // SHAND_TO_WEAK_INCLUDE 24 | 25 | -------------------------------------------------------------------------------- /libs/angle/example/angle_example.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Akira Takahashi 2014 2 | // Use, modification and distribution is subject to the Boost Software License, 3 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | #include 8 | 9 | int main() 10 | { 11 | shand::degree_f deg(45.0f); 12 | shand::radian_f rad = shand::angle_cast(deg); 13 | 14 | std::cout << rad.get() << std::endl; 15 | 16 | // shand::sin(deg); // compilation error 17 | shand::radian_f sin_result = shand::sin(rad); 18 | std::cout << sin_result.get() << std::endl; 19 | } 20 | -------------------------------------------------------------------------------- /shand/old/static_assert.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_STATIC_ASSERT_INCLUDE 2 | #define SHAND_STATIC_ASSERT_INCLUDE 3 | 4 | // Copyright Akira Takahashi 2007 5 | // Use, modification and distribution is subject to the Boost Software License, 6 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | namespace shand { 10 | 11 | template struct static_assertion_faire; 12 | template <> struct static_assertion_faire { enum { value = 1 }; }; 13 | 14 | #define SHAND_STATIC_ASSERT(Expression) shand::static_assertion_faire::value 15 | 16 | } // namespace shand 17 | 18 | #endif // SHAND_STATIC_ASSERT_INCLUDE 19 | 20 | -------------------------------------------------------------------------------- /shand/old/depend/to_string.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Akira Takahashi 2006 2 | // Use, modification and distribution is subject to the Boost Software License, 3 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | 7 | #ifndef SHAND_TO_CSTRING_INCLUDE 8 | #define SHAND_TO_CSTRING_INCLUDE 9 | 10 | #include 11 | 12 | template 13 | inline CString ToString(const Type& value) 14 | { 15 | #ifdef _UNICODE 16 | return shand::to_wstring(value).c_str(); 17 | #else 18 | return shand::to_string(value).c_str(); 19 | #endif // _UNICODE 20 | 21 | } 22 | 23 | 24 | #endif // SHAND_TO_CSTRING_INCLUDE 25 | 26 | -------------------------------------------------------------------------------- /shand/as_range.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_AS_RANGE_INCLUDE 2 | #define SHAND_AS_RANGE_INCLUDE 3 | 4 | // Copyright Akira Takahashi 2015 5 | // Use, modification and distribution is subject to the Boost Software License, 6 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | #include 11 | 12 | namespace shand { 13 | 14 | template 15 | boost::iterator_range as_range(std::pair p) 16 | { 17 | return boost::make_iterator_range(p.first, p.second); 18 | } 19 | 20 | } // namespace shand 21 | 22 | #endif // SHAND_AS_RANGE_INCLUDE 23 | 24 | -------------------------------------------------------------------------------- /libs/immutable_vector/example/example.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Akira Takahashi 2014 2 | // Use, modification and distribution is subject to the Boost Software License, 3 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | #include 8 | 9 | int main() 10 | { 11 | // add element, modify element, etc... 12 | shand::vector_builder v; 13 | v.push_back(1); 14 | v.push_back(2); 15 | v.push_back(3); 16 | 17 | // end modify 18 | shand::immutable_vector iv(std::move(v)); 19 | 20 | for (int x : iv) { 21 | std::cout << x << std::endl; 22 | } 23 | } 24 | 25 | -------------------------------------------------------------------------------- /libs/encoding_string/doc/reference/encoding_string/encoding_string/c_str.md: -------------------------------------------------------------------------------- 1 | # c_str 2 | ```cpp 3 | const char_type* c_str() const; 4 | ``` 5 | 6 | ## 概要 7 | C文字列を取得する。 8 | 9 | 10 | ## 戻り値 11 | C言語の文字列表現を返す。 12 | 13 | この関数によって返されるポインタの寿命は、`*this`オブジェクトと同じである。 14 | 15 | 16 | ## 計算量 17 | O(1) 18 | 19 | 20 | ## 備考 21 | この関数は、C言語のAPIに文字列を渡すために使用できる。 22 | 23 | 24 | ## 例 25 | ```cpp 26 | #include 27 | #include 28 | 29 | int main() 30 | { 31 | using namespace shand; 32 | 33 | encoding_string s = "hello"; 34 | const char* c = s.c_str(); 35 | 36 | std::cout << c << std::endl; 37 | } 38 | ``` 39 | 40 | ## 出力 41 | ``` 42 | hello 43 | ``` 44 | 45 | 46 | -------------------------------------------------------------------------------- /shand/io_adaptor/adapted/std_list.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_IO_ADAPTOR_ADAPTED_STD_LIST_INCLUDE 2 | #define SHAND_IO_ADAPTOR_ADAPTED_STD_LIST_INCLUDE 3 | 4 | #include 5 | #include "../traits.hpp" 6 | 7 | namespace std { 8 | 9 | template 10 | class list; 11 | 12 | } // namespace std 13 | 14 | namespace shand { namespace io_adaptors { 15 | 16 | template 17 | struct is_adapted > : boost::mpl::true_ {}; 18 | 19 | template 20 | struct tag_of > : boost::mpl::identity {}; 21 | 22 | }} // namespace shand::io_adaptors 23 | 24 | #endif // SHAND_IO_ADAPTOR_ADAPTED_STD_LIST_INCLUDE 25 | 26 | 27 | -------------------------------------------------------------------------------- /libs/as_range/example.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Akira Takahashi 2015 2 | // Use, modification and distribution is subject to the Boost Software License, 3 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | int main() 12 | { 13 | const std::multimap m = { 14 | {1, "apple"}, 15 | {2, "gorrila"}, 16 | {1, "bugle"} 17 | }; 18 | 19 | for (const auto& x : shand::as_range(m.equal_range(1))) { 20 | std::cout << x.second << std::endl; 21 | } 22 | } 23 | 24 | /* 25 | output: 26 | apple 27 | bugle 28 | */ 29 | -------------------------------------------------------------------------------- /shand/io_adaptor/adapted/std_deque.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_IO_ADAPTOR_ADAPTED_STD_DEQUE_INCLUDE 2 | #define SHAND_IO_ADAPTOR_ADAPTED_STD_DEQUE_INCLUDE 3 | 4 | #include 5 | #include "../traits.hpp" 6 | 7 | namespace std { 8 | 9 | template 10 | class deque; 11 | 12 | } // namespace std 13 | 14 | namespace shand { namespace io_adaptors { 15 | 16 | template 17 | struct is_adapted > : boost::mpl::true_ {}; 18 | 19 | template 20 | struct tag_of > : boost::mpl::identity {}; 21 | 22 | }} // namespace shand::io_adaptors 23 | 24 | #endif // SHAND_IO_ADAPTOR_ADAPTED_STD_DEQUE_INCLUDE 25 | 26 | 27 | -------------------------------------------------------------------------------- /shand/io_adaptor/adapted/std_vector.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_IO_ADAPTOR_ADAPTED_STD_VECTOR_INCLUDE 2 | #define SHAND_IO_ADAPTOR_ADAPTED_STD_VECTOR_INCLUDE 3 | 4 | #include 5 | #include "../traits.hpp" 6 | 7 | namespace std { 8 | 9 | template 10 | class vector; 11 | 12 | } // namespace std 13 | 14 | namespace shand { namespace io_adaptors { 15 | 16 | template 17 | struct is_adapted > : boost::mpl::true_ {}; 18 | 19 | template 20 | struct tag_of > : boost::mpl::identity {}; 21 | 22 | }} // namespace shand::io_adaptors 23 | 24 | #endif // SHAND_IO_ADAPTOR_ADAPTED_STD_VECTOR_INCLUDE 25 | 26 | 27 | -------------------------------------------------------------------------------- /libs/encoding_string/doc/reference/encoding_string/encoding_string/codeunit_at.md: -------------------------------------------------------------------------------- 1 | # codeunit_at 2 | ```cpp 3 | value_type codeunit_at(std::size_t index) const; 4 | ``` 5 | 6 | ## 概要 7 | 任意の位置のコードユニットを取得する。 8 | 9 | 10 | ## 要件 11 | `index < codeunit_size()`であること。 12 | 13 | 14 | ## 戻り値 15 | `index`番目のコードユニットを返す。 16 | 17 | 18 | ## 計算量 19 | O(N) 20 | 21 | 22 | ## 例 23 | ```cpp 24 | #include 25 | #include 26 | 27 | int main() 28 | { 29 | using namespace shand; 30 | encoding_string s = u8"あいうえお"; 31 | 32 | // 2番目のコードユニット(u8"う")を取得 33 | encoding_string u = s.codeunit_at(2); 34 | std::cout << u << std::endl; 35 | } 36 | ``` 37 | 38 | ## 出力 39 | ``` 40 | う 41 | ``` 42 | 43 | 44 | -------------------------------------------------------------------------------- /libs/strict_types/strict_integer_example.cpp: -------------------------------------------------------------------------------- 1 | // disallow bool conversion integer 2 | // 3 | // Copyright Akira Takahashi 2013 4 | // Use, modification and distribution is subject to the Boost Software License, 5 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | #include 10 | 11 | int main() 12 | { 13 | shand::strict_integer x = 3; 14 | x = 2; 15 | std::cout << x.get() << std::endl; 16 | 17 | // shand::strict_integer y = false; // コンパイルエラー! 18 | 19 | // shand::strict_integer z = 3; 20 | // z = false; // コンパイルエラー! 21 | 22 | // OK 23 | if (x < 4) {} 24 | 25 | // コンパイルエラー! 26 | // if (x < false) {} 27 | } 28 | -------------------------------------------------------------------------------- /libs/strict_types/strict_bool_example.cpp: -------------------------------------------------------------------------------- 1 | // disallow integer/floating point conversion bool 2 | // 3 | // Copyright Akira Takahashi 2013 4 | // Use, modification and distribution is subject to the Boost Software License, 5 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | #include 10 | 11 | int main() 12 | { 13 | shand::strict_bool x = true; 14 | x = false; 15 | std::cout << std::boolalpha << x.get() << std::endl; 16 | 17 | // shand::strict_bool y = 3.0; // コンパイルエラー! 18 | 19 | // shand::strict_bool z = true; 20 | // z = 3.0; // コンパイルエラー! 21 | 22 | // OK 23 | if (x < true) {} 24 | 25 | // コンパイルエラー! 26 | // if (x < 3) {} 27 | } 28 | -------------------------------------------------------------------------------- /libs/special_value/example/example.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Akira Takahashi 2014 2 | // Use, modification and distribution is subject to the Boost Software License, 3 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | #include 8 | 9 | enum class PopType { Root }; 10 | std::string popToString(PopType) { return "Root"; } 11 | 12 | int main() 13 | { 14 | shand::special_value pop_count = 1u; 15 | // pop_count = PopType::Root; 16 | 17 | pop_count.on_value([](std::size_t value) { 18 | std::cout << value << std::endl; 19 | }) 20 | .on_enum([](PopType pop) { 21 | std::cout << popToString(pop) << std::endl; 22 | }); 23 | } 24 | -------------------------------------------------------------------------------- /libs/strict_types/strict_real_example.cpp: -------------------------------------------------------------------------------- 1 | // disallow bool conversion floating point 2 | // 3 | // Copyright Akira Takahashi 2013 4 | // Use, modification and distribution is subject to the Boost Software License, 5 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | #include 10 | 11 | int main() 12 | { 13 | shand::strict_real x = 3.0f; 14 | x = 2.0f; 15 | std::cout << x.get() << std::endl; 16 | 17 | // shand::strict_real y = false; // コンパイルエラー! 18 | 19 | // shand::strict_real z = 3.0f; 20 | // z = false; // コンパイルエラー! 21 | 22 | // OK 23 | if (x < 4.0f) {} 24 | 25 | // コンパイルエラー! 26 | // if (x < false) {} 27 | } 28 | -------------------------------------------------------------------------------- /shand/old/assign/deque.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_ASSIGN_DEQUE_INCLUDE 2 | #define SHAND_ASSIGN_DEQUE_INCLUDE 3 | 4 | // Copyright Thorsten Ottosen 2003-2004. 5 | // Copyright Akira Takahashi 2007 6 | // Use, modification and distribution is subject to the Boost Software License, 7 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 8 | // http://www.boost.org/LICENSE_1_0.txt) 9 | 10 | #include 11 | #include "list_inserter.hpp" 12 | 13 | namespace shand { namespace assign { 14 | 15 | template 16 | inline list_inserter > > 17 | operator+=(std::deque& container, Type value) 18 | { 19 | return push_back(container)(value); 20 | } 21 | 22 | }} // namespace shand::assign 23 | 24 | #endif // SHAND_ASSIGN_DEQUE_INCLUDE 25 | 26 | -------------------------------------------------------------------------------- /shand/old/assign/list.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_ASSIGN_LIST_INCLUDE 2 | #define SHAND_ASSIGN_LIST_INCLUDE 3 | 4 | // Copyright Thorsten Ottosen 2003-2004. 5 | // Copyright Akira Takahashi 2007 6 | // Use, modification and distribution is subject to the Boost Software License, 7 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 8 | // http://www.boost.org/LICENSE_1_0.txt) 9 | 10 | 11 | #include 12 | #include "list_inserter.hpp" 13 | 14 | namespace shand { namespace assign { 15 | 16 | template 17 | inline list_inserter > > 18 | operator+=(std::list& container, Type value) 19 | { 20 | return push_back(container)(value); 21 | } 22 | 23 | }} // namespace shand::assign 24 | 25 | #endif // SHAND_ASSIGN_LIST_INCLUDE 26 | 27 | -------------------------------------------------------------------------------- /shand/old/assign/queue.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_ASSIGN_QUEUE_INCLUDE 2 | #define SHAND_ASSIGN_QUEUE_INCLUDE 3 | 4 | // Copyright Thorsten Ottosen 2003-2004. 5 | // Copyright Akira Takahashi 2007 6 | // Use, modification and distribution is subject to the Boost Software License, 7 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 8 | // http://www.boost.org/LICENSE_1_0.txt) 9 | 10 | 11 | #include 12 | #include "list_inserter.hpp" 13 | 14 | namespace shand { namespace assign { 15 | 16 | template 17 | inline list_inserter > > 18 | operator+=(std::queue& container, Type value) 19 | { 20 | return push(container)(value); 21 | } 22 | 23 | }} // namespace shand::assign 24 | 25 | #endif // SHAND_ASSIGN_QUEUE_INCLUDE 26 | 27 | -------------------------------------------------------------------------------- /shand/old/assign/stack.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_ASSIGN_STACK_INCLUDE 2 | #define SHAND_ASSIGN_STACK_INCLUDE 3 | 4 | // Copyright Thorsten Ottosen 2003-2004. 5 | // Copyright Akira Takahashi 2007 6 | // Use, modification and distribution is subject to the Boost Software License, 7 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 8 | // http://www.boost.org/LICENSE_1_0.txt) 9 | 10 | 11 | #include 12 | #include "list_inserter.hpp" 13 | 14 | namespace shand { namespace assign { 15 | 16 | template 17 | inline list_inserter > > 18 | operator+=(std::stack& container, Type value) 19 | { 20 | return push(container)(value); 21 | } 22 | 23 | }} // namespace shand::assign 24 | 25 | #endif // SHAND_ASSIGN_STACK_INCLUDE 26 | 27 | -------------------------------------------------------------------------------- /libs/optional_algorithm/test/map_find.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Akira Takahashi 2012 2 | // Use, modification and distribution is subject to the Boost Software License, 3 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | 12 | int main() 13 | { 14 | std::map m; 15 | 16 | m["Akira"] = 24; 17 | m["Millia"] = 16; 18 | m["Johnny"] = 38; 19 | 20 | if (boost::optional value = shand::map_find(m, "Akira")) 21 | BOOST_TEST(value.get() == 24); 22 | else 23 | BOOST_ERROR("Not Found"); 24 | 25 | return boost::report_errors(); 26 | } 27 | 28 | -------------------------------------------------------------------------------- /shand/spirit_qi/valid_check.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_SPIRIT_QI_VALID_CHECK_INCLUDE 2 | #define SHAND_SPIRIT_QI_VALID_CHECK_INCLUDE 3 | 4 | #include 5 | 6 | namespace shand { namespace spirit_qi { 7 | 8 | template 9 | struct valid_check_t { 10 | Expr expr; 11 | 12 | valid_check_t(const Expr& expr_) 13 | : expr(expr_) {} 14 | 15 | template 16 | void operator()(const T& x, boost::spirit::unused_type, bool& pass) const 17 | { 18 | pass = expr(x); 19 | } 20 | }; 21 | 22 | template 23 | inline valid_check_t valid_check(const Expr& expr) 24 | { 25 | return valid_check_t(expr); 26 | } 27 | 28 | }} // namespace shand::spirit_qi 29 | 30 | #endif // SHAND_SPIRIT_QI_VALID_CHECK_INCLUDE 31 | 32 | 33 | -------------------------------------------------------------------------------- /shand/old/assign/vector.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_ASSIGN_VECTOR_INCLUDE 2 | #define SHAND_ASSIGN_VECTOR_INCLUDE 3 | 4 | // Copyright Thorsten Ottosen 2003-2004. 5 | // Copyright Akira Takahashi 2007 6 | // Use, modification and distribution is subject to the Boost Software License, 7 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 8 | // http://www.boost.org/LICENSE_1_0.txt) 9 | 10 | 11 | #include 12 | #include "list_inserter.hpp" 13 | 14 | namespace shand { namespace assign { 15 | 16 | template 17 | inline list_inserter > > 18 | operator+=(std::vector& container, Type value) 19 | { 20 | return push_back(container)(value); 21 | } 22 | 23 | }} // namespace shand::assign 24 | 25 | #endif // SHAND_ASSIGN_VECTOR_INCLUDE 26 | 27 | -------------------------------------------------------------------------------- /libs/fusion/example/adjacency_for_each.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Akira Takahashi 2012 2 | // Use, modification and distribution is subject to the Boost Software License, 3 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | namespace fusion = boost::fusion; 12 | 13 | struct disper { 14 | template 15 | void operator()(const Seq& seq) const 16 | { 17 | std::cout << seq << std::endl; 18 | } 19 | }; 20 | 21 | int main() 22 | { 23 | const fusion::vector v(1, 'a', 3.14); 24 | 25 | shand::fusion::adjacency_for_each(v, disper()); 26 | } 27 | 28 | -------------------------------------------------------------------------------- /libs/strong_typedef/test_hash.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Akira Takahashi 2012-2014 2 | // Use, modification and distribution is subject to the Boost Software License, 3 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | struct tag {}; 13 | typedef shand::tagged_int integer; 14 | 15 | int main () 16 | { 17 | { 18 | std::unordered_map m; 19 | m.insert(std::make_pair(integer(3), 'a')); 20 | } 21 | { 22 | boost::unordered_map m; 23 | m.insert(std::make_pair(integer(3), 'a')); 24 | } 25 | 26 | return boost::report_errors(); 27 | } 28 | 29 | -------------------------------------------------------------------------------- /shand/old/io.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_0X_IO_INCLUDE 2 | #define SHAND_0X_IO_INCLUDE 3 | 4 | // Copyright Akira Takahashi 2007 5 | // Use, modification and distribution is subject to the Boost Software License, 6 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | template 14 | void print_detail(std::size_t count, const std::string& fmt, const Head& head, const Tail&... tail) 15 | { 16 | std::cout << head << std::endl; 17 | 18 | if (count > 0) 19 | print_detail(count-1, fmt, tail...); 20 | } 21 | 22 | template 23 | void print(const std::string& fmt, const Args&... args) 24 | { 25 | print_detail(sizeof...(args), fmt, args...); 26 | } 27 | 28 | #endif // SHAND_0X_IO_INCLUDE 29 | 30 | -------------------------------------------------------------------------------- /libs/strong_typedef/tagged_int_example.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Akira Takahashi 2012 2 | // Use, modification and distribution is subject to the Boost Software License, 3 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | struct count_tag {}; 11 | struct seconds_tag {}; 12 | 13 | int main() 14 | { 15 | shand::tagged_int count(0); 16 | shand::tagged_int seconds(std::time(0)); 17 | 18 | // 異なる型(タグ)間での暗黙変換はできない 19 | // count = seconds; // コンパイルエラー!型が違う 20 | 21 | std::cout << count << std::endl; 22 | std::cout << seconds << std::endl; 23 | } 24 | 25 | /* 26 | possible output: 27 | 0 28 | 1353483810 29 | */ 30 | 31 | -------------------------------------------------------------------------------- /libs/match/example/match.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Akira Takahashi 2015 2 | // Use, modification and distribution is subject to the Boost Software License, 3 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | int main() 11 | { 12 | boost::optional a = 3; 13 | shand::match(a, [](int& x) { 14 | std::cout << x << std::endl; 15 | }); 16 | 17 | boost::optional b; 18 | shand::match(b, [] { 19 | std::cout << "none" << std::endl; 20 | }); 21 | 22 | // 2 arguments version 23 | shand::match(a, 24 | [](int& x) { std::cout << x << std::endl; }, 25 | [] { std::cout << "none" << std::endl; } 26 | ); 27 | } 28 | 29 | /* 30 | output: 31 | 3 32 | none 33 | 3 34 | */ 35 | 36 | -------------------------------------------------------------------------------- /shand/old/switch.hpp: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDE_SWITCH_VALUE_ 2 | #define INCLUDE_SWITCH_VALUE_ 3 | 4 | // Copyright Akira Takahashi 2007 5 | // Use, modification and distribution is subject to the Boost Software License, 6 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #define switch_ex(value) switch(int switch_value = (value)) 10 | 11 | #endif // INCLUDE_SWITCH_VALUE_ 12 | 13 | //------------------------------------------ 14 | // Sample 15 | //------------------------------------------ 16 | // int main() 17 | // { 18 | // int value = 3; 19 | // 20 | // switch_ex (value) { 21 | // case 3: 22 | // cout << switch_value << endl; 23 | // break; 24 | // default: 25 | // break; 26 | // } 27 | // return 0; 28 | // } 29 | // 30 | //----------------------------------------- 31 | // 3 32 | // 33 | // 34 | -------------------------------------------------------------------------------- /libs/trace_value/example.cpp: -------------------------------------------------------------------------------- 1 | #define BOOST_STACKTRACE_HEADER_ONLY 2 | #define BOOST_STACKTRACE_USE_BACKTRACE 3 | #include 4 | #include 5 | 6 | shand::trace_value value; 7 | 8 | void f() 9 | { 10 | value = 1; 11 | } 12 | 13 | int main() 14 | { 15 | f(); 16 | value.output_trace(std::cout); 17 | } 18 | 19 | /* 20 | output: 21 | 0# boost::stacktrace::detail::backtrace_holder::backtrace_holder() 22 | 1# boost::stacktrace::detail::backtrace_holder::backtrace_holder() 23 | 2# boost::stacktrace::stacktrace::stacktrace() 24 | 3# boost::stacktrace::stacktrace::stacktrace() 25 | 4# shand::trace_value& shand::trace_value::modify_this::operator=(int)::'lambda'()>(shand::trace_value::operator=(int)::'lambda'()) 26 | 5# shand::trace_value::operator=(int) 27 | 6# f() 28 | 7# main 29 | 8# start 30 | */ 31 | -------------------------------------------------------------------------------- /libs/encoding_string/doc/reference/encoding_string/encoding_string/raw_str.md: -------------------------------------------------------------------------------- 1 | # raw_str 2 | ```cpp 3 | const string_type& raw_str() const; 4 | ``` 5 | 6 | ## 概要 7 | [`basic_string`](https://cpprefjp.github.io/reference/string/basic_string.html)文字列を取得する。 8 | 9 | 10 | ## 戻り値 11 | [`basic_string`](https://cpprefjp.github.io/reference/string/basic_string.html)表現の文字列への参照を返す。 12 | 13 | この関数によって返される参照の寿命は、`*this`オブジェクトと同じである。 14 | 15 | 16 | ## 計算量 17 | O(1) 18 | 19 | 20 | ## 備考 21 | この関数は、文字列のバイト表現に関するプロパティを取得するために使用できる。 22 | 23 | 24 | ## 例 25 | ```cpp 26 | #include 27 | #include 28 | 29 | int main() 30 | { 31 | using namespace shand; 32 | 33 | encoding_string s = "hello"; 34 | const std::string raw = s.raw_str(); 35 | 36 | std::cout << raw << std::endl; 37 | } 38 | ``` 39 | 40 | ## 出力 41 | ``` 42 | hello 43 | ``` 44 | 45 | 46 | -------------------------------------------------------------------------------- /libs/spirit_qi/example/valid_check.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Akira Takahashi 2012 2 | // Use, modification and distribution is subject to the Boost Software License, 3 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | namespace qi = boost::spirit::qi; 13 | using namespace boost::lambda; 14 | 15 | using shand::spirit_qi::valid_check; 16 | 17 | int main() 18 | { 19 | const std::string s = "3"; 20 | 21 | std::string::const_iterator it = s.begin(); 22 | if (!qi::parse(it, s.end(), qi::int_[valid_check(_1 == 2)])) { 23 | std::cout << "fail" << std::endl; 24 | } 25 | else { 26 | std::cout << "success" << std::endl; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /shand/old/depend/cstring_format.h: -------------------------------------------------------------------------------- 1 | #ifndef _CSTRING_FORMAT_H_ 2 | #define _CSTRING_FORMAT_H_ 3 | 4 | // Copyright Akira Takahashi 2007 5 | // Use, modification and distribution is subject to the Boost Software License, 6 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | 10 | // ※ MFC, ATL/WTL用 11 | 12 | inline CString FormatString(LPCTSTR lpszFormat, ...) 13 | { 14 | CString strFmt; 15 | 16 | va_list argList; 17 | va_start(argList, lpszFormat); 18 | strFmt.FormatV(lpszFormat, argList); 19 | return strFmt; 20 | } 21 | 22 | //------------------------------------------// 23 | // sample // 24 | //==========================================// 25 | // AfxMessageBox(FormatString("%d", 314)); // 26 | // // 27 | // CString str = FormatString("%f", 3.14); // 28 | //------------------------------------------// 29 | 30 | #endif // _CSTRING_FORMAT_H_ 31 | -------------------------------------------------------------------------------- /libs/encoding_string/doc/reference/encoding_string/encoding_string/end.md: -------------------------------------------------------------------------------- 1 | # end 2 | ```cpp 3 | iterator end(); 4 | const_iterator end() const; 5 | ``` 6 | 7 | ## 概要 8 | 末尾コードユニットの次を指すイテレータを取得する。 9 | 10 | 11 | ## 戻り値 12 | 末尾コードユニットの次を指すイテレータを返す。 13 | 14 | 15 | ## 例 16 | ```cpp 17 | #include 18 | #include 19 | #include 20 | 21 | int main() 22 | { 23 | using namespace shand; 24 | encoding_string s = u8"あいうえお"; 25 | 26 | // コードユニットを一つずつ出力 27 | std::for_each(s.begin(), s.end(), [](const encoding_string& c) { 28 | std::cout << c << std::endl; 29 | }); 30 | 31 | std::cout << std::endl; 32 | 33 | // 範囲for文にも適用可能 34 | for (const encoding_string& c : s) { 35 | std::cout << c << std::endl; 36 | } 37 | } 38 | ``` 39 | 40 | ## 出力 41 | ``` 42 | あ 43 | い 44 | う 45 | え 46 | お 47 | 48 | あ 49 | い 50 | う 51 | え 52 | お 53 | ``` 54 | 55 | 56 | -------------------------------------------------------------------------------- /libs/optional_algorithm/test/find_if.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Akira Takahashi 2012 2 | // Use, modification and distribution is subject to the Boost Software License, 3 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | using boost::lambda::_1; 14 | 15 | int main() 16 | { 17 | const std::vector v = boost::assign::list_of(3)(1)(4); 18 | if (boost::optional p = shand::find_if(v, _1 % 2 == 0)) { 19 | BOOST_TEST(p.get() == 4); 20 | } 21 | else { 22 | BOOST_ERROR("find_if failed!"); 23 | } 24 | 25 | boost::optional failed = shand::find_if(v, _1 == 5); 26 | BOOST_TEST(!failed); 27 | 28 | return boost::report_errors(); 29 | } 30 | 31 | -------------------------------------------------------------------------------- /shand/old/mpl/if.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_MPL_IF_INCLUDE 2 | #define SHAND_MPL_IF_INCLUDE 3 | 4 | // Copyright Aleksey Gurtovoy 2000-2004 5 | // Copyright Akira Takahashi 2007 6 | // Use, modification and distribution is subject to the Boost Software License, 7 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 8 | // http://www.boost.org/LICENSE_1_0.txt) 9 | 10 | 11 | namespace shand { namespace mpl { 12 | 13 | // if_c 14 | template 15 | struct if_c; 16 | 17 | template 18 | struct if_c { 19 | typedef Then type; 20 | }; 21 | 22 | template 23 | struct if_c { 24 | typedef Else type; 25 | }; 26 | 27 | 28 | // if_ 29 | template 30 | struct if_ { 31 | typedef typename if_c::type type; 32 | }; 33 | 34 | } } // namespace shand::mpl 35 | 36 | #endif // SHAND_MPL_IF_INCLUDE 37 | 38 | -------------------------------------------------------------------------------- /libs/graph_literal/example/graph_literal.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Akira Takahashi 2012 2 | // Use, modification and distribution is subject to the Boost Software License, 3 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | enum vertex_type { A, B, C, D, N }; 13 | const std::string name = "ABCD"; 14 | 15 | int main() 16 | { 17 | typedef 18 | boost::adjacency_list 19 | graph_type; 20 | 21 | using shand::vertex; 22 | graph_type g = ( 23 | vertex(A) >= vertex(B) & 24 | vertex(A) >= vertex(C) >= vertex(D) 25 | ); 26 | 27 | std::ofstream file("test.dot"); 28 | boost::write_graphviz(file, g, boost::make_label_writer(name.c_str())); 29 | } 30 | 31 | -------------------------------------------------------------------------------- /shand/optional_algorithm/map_find.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_OPTIONAL_ALGORITHM_MAP_FIND_INCLUDE 2 | #define SHAND_OPTIONAL_ALGORITHM_MAP_FIND_INCLUDE 3 | 4 | // Shand Optional Algorithm Library 5 | // 6 | // Copyright Akira Takahashi 2011 7 | // Use, modification and distribution is subject to the Boost Software License, 8 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 9 | // http://www.boost.org/LICENSE_1_0.txt) 10 | 11 | #include 12 | 13 | namespace shand { namespace optional_algorithm { 14 | 15 | template 16 | inline boost::optional 17 | map_find(const Map& m, const Key& key) 18 | { 19 | typename Map::const_iterator it = m.find(key); 20 | return it != m.end() ? it->second : boost::optional(); 21 | } 22 | 23 | } // namespace optional_algorithm 24 | 25 | using optional_algorithm::map_find; 26 | 27 | } // namespace shand 28 | 29 | #endif // SHAND_OPTIONAL_ALGORITHM_MAP_FIND_INCLUDE 30 | 31 | -------------------------------------------------------------------------------- /shand/old/assign/set.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_ASSIGN_SET_INCLUDE 2 | #define SHAND_ASSIGN_SET_INCLUDE 3 | 4 | // Copyright Thorsten Ottosen 2003-2004. 5 | // Copyright Akira Takahashi 2007 6 | // Use, modification and distribution is subject to the Boost Software License, 7 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 8 | // http://www.boost.org/LICENSE_1_0.txt) 9 | 10 | 11 | #include 12 | #include "list_inserter.hpp" 13 | 14 | namespace shand { namespace assign { 15 | 16 | template 17 | inline list_inserter > > 18 | operator+=(std::set& container, Type value) 19 | { 20 | return insert(container)(value); 21 | } 22 | 23 | template 24 | inline list_inserter > > 25 | operator+=(std::multiset& container, Type value) 26 | { 27 | return insert(container)(value); 28 | } 29 | 30 | }} // namespace shand::assign 31 | 32 | #endif // SHAND_ASSIGN_SET_INCLUDE 33 | 34 | -------------------------------------------------------------------------------- /shand/strong_typedef/tagged_int_io.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_TAGGED_INT_IO_INCLUDE 2 | #define SHAND_TAGGED_INT_IO_INCLUDE 3 | 4 | // strong typedef for integer types. 5 | // 6 | // Copyright Akira Takahashi 2012 7 | // Use, modification and distribution is subject to the Boost Software License, 8 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 9 | // http://www.boost.org/LICENSE_1_0.txt) 10 | 11 | #include 12 | #include "./tagged_int.hpp" 13 | 14 | namespace shand { 15 | 16 | template 17 | std::basic_ostream& 18 | operator<<(std::basic_ostream& os, const tagged_int& x) 19 | { 20 | return os << x.get(); 21 | } 22 | 23 | template 24 | std::basic_istream& 25 | operator>>(std::basic_istream& is, tagged_int& x) 26 | { 27 | return is >> x.get(); 28 | } 29 | 30 | } // namespace shand 31 | 32 | #endif 33 | 34 | -------------------------------------------------------------------------------- /shand/algorithm/adjacent_for_each.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_ALGORITHM_ADJACENT_FOR_EACH_INCLUDE 2 | #define SHAND_ALGORITHM_ADJACENT_FOR_EACH_INCLUDE 3 | 4 | // Copyright Akira Takahashi 2015 5 | // Use, modification and distribution is subject to the Boost Software License, 6 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | #include 9 | 10 | namespace shand { 11 | 12 | template 13 | void adjacent_for_each(const InputRange& range, BinaryFunction f) 14 | { 15 | // for ADL 16 | using std::begin; 17 | using std::end; 18 | 19 | auto first = begin(range); 20 | auto last = end(range); 21 | 22 | if (first == last) 23 | return; 24 | 25 | while (std::next(first) != last) { 26 | const auto& a = *first; 27 | ++first; 28 | const auto& b = *first; 29 | f(a, b); 30 | } 31 | } 32 | 33 | } // namespace shand 34 | 35 | #endif // SHAND_ALGORITHM_ADJACENT_FOR_EACH_INCLUDE 36 | 37 | -------------------------------------------------------------------------------- /libs/encoding_string/doc/reference/encoding_string/encoding_string/begin.md: -------------------------------------------------------------------------------- 1 | # begin 2 | ```cpp 3 | iterator begin(); 4 | const_iterator begin() const; 5 | ``` 6 | 7 | ## 概要 8 | 先頭のコードユニットを指すイテレータを取得する。 9 | 10 | 11 | ## 戻り値 12 | 先頭のコードユニットを指すイテレータを返す。 13 | 14 | このイテレータは、コードユニット単位で走査を行う。ひとつのコードユニットは、`encoding_string`オブジェクトとして表現される。 15 | 16 | 17 | ## 例 18 | ```cpp 19 | #include 20 | #include 21 | #include 22 | 23 | int main() 24 | { 25 | using namespace shand; 26 | encoding_string s = u8"あいうえお"; 27 | 28 | // コードユニットを一つずつ出力 29 | std::for_each(s.begin(), s.end(), [](const encoding_string& c) { 30 | std::cout << c << std::endl; 31 | }); 32 | 33 | std::cout << std::endl; 34 | 35 | // 範囲for文にも適用可能 36 | for (const encoding_string& c : s) { 37 | std::cout << c << std::endl; 38 | } 39 | } 40 | ``` 41 | 42 | ## 出力 43 | ``` 44 | あ 45 | い 46 | う 47 | え 48 | お 49 | 50 | あ 51 | い 52 | う 53 | え 54 | お 55 | ``` 56 | 57 | 58 | -------------------------------------------------------------------------------- /shand/old/mpl/eval_if.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_MPL_EVAL_IF_INCLUDE 2 | #define SHAND_MPL_EVAL_IF_INCLUDE 3 | 4 | // Copyright Aleksey Gurtovoy 2000-2004 5 | // Copyright Akira Takahashi 2007 6 | // Use, modification and distribution is subject to the Boost Software License, 7 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 8 | // http://www.boost.org/LICENSE_1_0.txt) 9 | 10 | namespace shand { namespace mpl { 11 | 12 | // eval_if_c 13 | template 14 | struct eval_if_c; 15 | 16 | template 17 | struct eval_if_c { 18 | typedef typename Then::type type; 19 | }; 20 | 21 | template 22 | struct eval_if_c { 23 | typedef typename Else::type type; 24 | }; 25 | 26 | 27 | // eval_if 28 | template 29 | struct eval_if { 30 | typedef typename eval_if_c::type type; 31 | }; 32 | 33 | 34 | }} // namespace shand::mpl 35 | 36 | #endif // SHAND_MPL_EVAL_IF_INCLUDE 37 | 38 | -------------------------------------------------------------------------------- /shand/old/assign/map.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_ASSIGN_MAP_INCLUDE 2 | #define SHAND_ASSIGN_MAP_INCLUDE 3 | 4 | // Copyright Thorsten Ottosen 2003-2004. 5 | // Copyright Akira Takahashi 2007 6 | // Use, modification and distribution is subject to the Boost Software License, 7 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 8 | // http://www.boost.org/LICENSE_1_0.txt) 9 | 10 | 11 | #include 12 | #include "list_inserter.hpp" 13 | 14 | namespace shand { namespace assign { 15 | 16 | template 17 | inline list_inserter > > 18 | operator+=(std::map& container, Pair value) 19 | { 20 | return insert(container)(value); 21 | } 22 | 23 | template 24 | inline list_inserter > > 25 | operator+=(std::multimap& container, Pair value) 26 | { 27 | return insert(container)(value); 28 | } 29 | 30 | }} // namespace shand::assign 31 | 32 | #endif // SHAND_ASSIGN_MAP_INCLUDE 33 | 34 | -------------------------------------------------------------------------------- /libs/optional_algorithm/test/max_element.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Akira Takahashi 2012 2 | // Use, modification and distribution is subject to the Boost Software License, 3 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | 12 | int main() 13 | { 14 | const std::vector v = boost::assign::list_of(3)(1)(4); 15 | if (boost::optional p = shand::max_element(v)) { 16 | BOOST_TEST(p.get() == 1); 17 | } 18 | else { 19 | BOOST_ERROR("max_element failed! Though the element exists."); 20 | } 21 | 22 | const std::vector v2; 23 | if (boost::optional p = shand::max_element(v2)) { 24 | BOOST_ERROR("max_element must not successed. range is empty."); 25 | } 26 | else { 27 | BOOST_TEST(true); 28 | } 29 | 30 | return boost::report_errors(); 31 | } 32 | 33 | -------------------------------------------------------------------------------- /libs/optional_algorithm/test/min_element.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Akira Takahashi 2012 2 | // Use, modification and distribution is subject to the Boost Software License, 3 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | 12 | int main() 13 | { 14 | const std::vector v = boost::assign::list_of(3)(1)(4); 15 | if (boost::optional p = shand::min_element(v)) { 16 | BOOST_TEST(p.get() == 1); 17 | } 18 | else { 19 | BOOST_ERROR("min_element failed! Though the element exists."); 20 | } 21 | 22 | const std::vector v2; 23 | if (boost::optional p = shand::min_element(v2)) { 24 | BOOST_ERROR("min_element must not successed. range is empty."); 25 | } 26 | else { 27 | BOOST_TEST(true); 28 | } 29 | 30 | return boost::report_errors(); 31 | } 32 | 33 | -------------------------------------------------------------------------------- /shand/strong_typedef/tagged_float_io.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_TAGGED_FLOAT_IO_INCLUDE 2 | #define SHAND_TAGGED_FLOAT_IO_INCLUDE 3 | 4 | // strong typedef for floating point types. 5 | // 6 | // Copyright Akira Takahashi 2012 7 | // Use, modification and distribution is subject to the Boost Software License, 8 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 9 | // http://www.boost.org/LICENSE_1_0.txt) 10 | 11 | #include 12 | #include "./tagged_float.hpp" 13 | 14 | namespace shand { 15 | 16 | template 17 | std::basic_ostream& 18 | operator<<(std::basic_ostream& os, const tagged_float& x) 19 | { 20 | return os << x.get(); 21 | } 22 | 23 | template 24 | std::basic_istream& 25 | operator>>(std::basic_istream& is, tagged_float& x) 26 | { 27 | return is >> x.get(); 28 | } 29 | 30 | } // namespace shand 31 | 32 | #endif 33 | 34 | -------------------------------------------------------------------------------- /libs/encoding_string/example.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Akira Takahashi 2013 2 | // Use, modification and distribution is subject to the Boost Software License, 3 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | #include 8 | 9 | int main() 10 | { 11 | using namespace shand; 12 | const encoding_string s = u8"あいうえお"; 13 | 14 | // 文字数を取得 15 | std::cout << s.codeunit_size() << std::endl; // 5 16 | 17 | // i番目の文字を取得 18 | std::cout << s.codeunit_at(2) << std::endl; // u8"う" 19 | 20 | // 1文字ずつ出力 21 | for (decltype(s)::value_type c : s) { 22 | std::cout << c << std::endl; 23 | } 24 | // あ 25 | // い 26 | // う 27 | // え 28 | // お 29 | 30 | // システムの文字コードで出力 31 | // WindowsではCP932で出力する 32 | std::cout << s << std::endl; // "あいうえお" 33 | 34 | // 部分文字列を取得 35 | encoding_string sub = s.codeunit_substr(2, 3); 36 | std::cout << sub << std::endl; // "うえお" 37 | } 38 | 39 | -------------------------------------------------------------------------------- /libs/random/random_device_example.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Akira Takahashi 2014. 2 | // Use, modification and distribution is subject to the Boost Software License, 3 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | // 6 | // Original implementation's license : 7 | // Copyright Jens Maurer 2000 8 | // Copyright Steven Watanabe 2010-2011 9 | // Distributed under the Boost Software License, Version 1.0. (See 10 | // accompanying file LICENSE_1_0.txt or copy at 11 | // http://www.boost.org/LICENSE_1_0.txt) 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | int main() 18 | { 19 | shand::random_device_32 rd32; 20 | std::cout << rd32() << std::endl; 21 | std::cout << rd32() << std::endl; 22 | 23 | shand::random_device_64 rd64; 24 | std::cout << rd64() << std::endl; 25 | std::cout << rd64() << std::endl; 26 | 27 | // make 32 bit seed 28 | std::mt19937 gen(rd32()); 29 | 30 | // make 64 bit seed 31 | std::mt19937_64 gen64(rd64()); 32 | } 33 | -------------------------------------------------------------------------------- /libs/round/test.cpp: -------------------------------------------------------------------------------- 1 | // Round utilities. 2 | // 3 | // Copyright Akira Takahashi 2013 4 | // Use, modification and distribution is subject to the Boost Software License, 5 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | #include 10 | 11 | int main() 12 | { 13 | { 14 | const int x = shand::round_to(1.4); 15 | BOOST_TEST(x == 1); 16 | 17 | const int y = shand::round_to(1.5); 18 | BOOST_TEST(y == 2); 19 | } 20 | { 21 | const int x = shand::round_even_to(1.5); 22 | BOOST_TEST(x == 2); 23 | 24 | const int y = shand::round_even_to(2.5); 25 | BOOST_TEST(y == 2); 26 | 27 | BOOST_TEST(shand::round_even_to(-1.5) == -2); 28 | BOOST_TEST(shand::round_even_to(-1.7) == -2); 29 | } 30 | { 31 | const int x = shand::ceil_to(1.4); 32 | BOOST_TEST(x == 2); 33 | } 34 | { 35 | const int x = shand::floor_to(1.6); 36 | BOOST_TEST(x == 1); 37 | } 38 | return boost::report_errors(); 39 | } 40 | -------------------------------------------------------------------------------- /libs/static_map/test/test.cpp: -------------------------------------------------------------------------------- 1 | // Compile time fixed capacity map. 2 | // 3 | // Copyright Akira Takahashi 2013 4 | // Use, modification and distribution is subject to the Boost Software License, 5 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | #include 10 | 11 | void construct_and_find_test() 12 | { 13 | shand::static_map map = { 14 | {'a', 1}, 15 | {'b', 2}, 16 | {'c', 3} 17 | }; 18 | 19 | BOOST_TEST(map.at('a') == 1); 20 | BOOST_TEST(map.at('b') == 2); 21 | BOOST_TEST(map.at('c') == 3); 22 | } 23 | 24 | void helper_function_test() 25 | { 26 | shand::pair_maker p; 27 | const auto map = shand::make_static_map( 28 | p('a', 1), 29 | p('b', 2), 30 | p('c', 3) 31 | ); 32 | 33 | BOOST_TEST(map.at('a') == 1); 34 | BOOST_TEST(map.at('b') == 2); 35 | BOOST_TEST(map.at('c') == 3); 36 | } 37 | 38 | int main() 39 | { 40 | construct_and_find_test(); 41 | helper_function_test(); 42 | 43 | return boost::report_errors(); 44 | } 45 | -------------------------------------------------------------------------------- /shand/fusion/adjacency_for_each.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_FUSION_ADJACENCY_FOR_EACH_INCLUDE 2 | #define SHAND_FUSION_ADJACENCY_FOR_EACH_INCLUDE 3 | 4 | // Boost.Fusion extension. adjacency_for_each algorithm. 5 | // 6 | // Copyright Akira Takahashi 2011 7 | // Use, modification and distribution is subject to the Boost Software License, 8 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 9 | // http://www.boost.org/LICENSE_1_0.txt) 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | namespace shand { namespace fusion { 16 | 17 | namespace result_of { 18 | 19 | template 20 | struct adjacency_for_each { 21 | typedef void type; 22 | }; 23 | 24 | } // namespace result_of 25 | 26 | template 27 | inline typename result_of::adjacency_for_each::type 28 | adjacency_for_each(const Seq& seq, F f) 29 | { 30 | namespace fusion = boost::fusion; 31 | return fusion::for_each(fusion::zip(seq, fusion::pop_front(seq)), f); 32 | } 33 | 34 | }} // namespace shand::fusion 35 | 36 | #endif // SHAND_FUSION_ADJACENCY_FOR_EACH_INCLUDE 37 | -------------------------------------------------------------------------------- /libs/eigen_la/example/angle_example.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() 6 | { 7 | const shand::la::vector2 p(0.0f, 0.0f); 8 | const shand::la::vector2 direction(0.0f, 1.0f); 9 | const shand::la::vector2 q(1.0f, 1.0f); 10 | 11 | // use dot 12 | { 13 | const shand::radian_f theta = shand::la::vector_angle(direction, q); 14 | std::cout << shand::angle_cast(theta) << std::endl; 15 | } 16 | 17 | // use atan2 18 | { 19 | const shand::la::vector2 v = (q - p).normalized(); 20 | const shand::radian_f theta = shand::atan2(v.y(), v.x()); 21 | std::cout << shand::angle_cast(theta) << std::endl; 22 | } 23 | 24 | // use matrix 25 | { 26 | const shand::la::vector2 v = (q - p).normalized(); 27 | 28 | const shand::la::rotation2d rotate = shand::la::make_rotation2d(v); 29 | const shand::radian_f theta = rotate.angle(); 30 | 31 | std::cout << shand::angle_cast(theta) << std::endl; 32 | } 33 | } 34 | 35 | /* 36 | result: 37 | 45 38 | 45 39 | 45 40 | */ 41 | -------------------------------------------------------------------------------- /libs/encoding_string/doc/reference/encoding_string/encoding_string/codeunit_substr.md: -------------------------------------------------------------------------------- 1 | # codeunit_substr 2 | ```cpp 3 | encoding_string codeunit_substr(std::size_t index, std::size_t codeunit_size) const; // (1) 4 | encoding_string codeunit_substr(std::size_t index) const; // (2) 5 | ``` 6 | 7 | ## 概要 8 | 部分文字列を取得する。 9 | 10 | 11 | ## 要件 12 | - `index < codeunit_size()`であること。 13 | - `codeunit_size > 0`であること。 14 | 15 | 16 | ## 戻り値 17 | - (1) : コードポイント範囲`[index, index + codeunit_size]`の文字列を抽出して返す。 18 | - (2) : コードポイント範囲`[index, end)`の文字列を抽出して返す。 19 | 20 | 21 | ## 計算量 22 | - O(N) 23 | - UTF-32はO(1) 24 | 25 | 26 | ## 例 27 | ```cpp 28 | #include 29 | #include 30 | 31 | int main() 32 | { 33 | using namespace shand; 34 | encoding_string s = u8"あいうえお"; 35 | 36 | // コードポイントの範囲[1, 1 + 3]を取得する 37 | encoding_string sub1 = s.codeunit_substr(1, 3); 38 | std::cout << sub1 << std::endl; 39 | 40 | // 1番目のコードポイントから終端までを取得する 41 | encoding_string sub2 = s.codeunit_substr(1); 42 | std::cout << sub2 << std::endl; 43 | } 44 | ``` 45 | 46 | ## 出力 47 | ``` 48 | いうえ 49 | いうえお 50 | ``` 51 | 52 | 53 | -------------------------------------------------------------------------------- /shand/old/log.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Akira Takahashi 2006 2 | // Use, modification and distribution is subject to the Boost Software License, 3 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | //------------------------------------------------------// 7 | // Name : simple_log // 8 | // Desc : 簡易ログ出力 // 9 | // Note : 出力ファイル名は log.txt // 10 | // // 11 | // Version : 1.00 2006/08/04 作成 // 12 | // // 13 | //------------------------------------------------------// 14 | 15 | #ifndef SHAND_SIMPLE_LOG_INCLUDE 16 | #define SHAND_SIMPLE_LOG_INCLUDE 17 | 18 | #include 19 | 20 | namespace shand { 21 | template 22 | void simple_log(const Type& output) 23 | { 24 | std::fstream file("log.txt", std::ios::out | std::ios::app); 25 | 26 | file << output << std::endl; 27 | } 28 | } // namespace shand 29 | 30 | #endif // SHAND_SIMPLE_LOG_INCLUDE 31 | 32 | //----------------------------------| 33 | // How to use | 34 | //----------------------------------| 35 | // | 36 | // simple_log(314); | 37 | // simple_log(3.14); | 38 | // simple_log("abc"); | 39 | // | 40 | //----------------------------------| 41 | -------------------------------------------------------------------------------- /libs/algorithm/test/adjacent_for_each.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Akira Takahashi 2015 2 | // Use, modification and distribution is subject to the Boost Software License, 3 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | int main() 12 | { 13 | { 14 | const std::vector input = {1, 2, 3}; 15 | const std::vector> expected = { 16 | {1, 2}, 17 | {2, 3} 18 | }; 19 | 20 | std::vector> result; 21 | shand::adjacent_for_each(input, [&result](int a, int b) { 22 | result.push_back(std::make_pair(a, b)); 23 | }); 24 | BOOST_TEST(result == expected); 25 | } 26 | { 27 | const std::vector input = {1}; 28 | shand::adjacent_for_each(input, [](int, int) { 29 | BOOST_TEST(false); 30 | }); 31 | } 32 | { 33 | const std::vector input = {}; 34 | shand::adjacent_for_each(input, [](int, int) { 35 | BOOST_TEST(false); 36 | }); 37 | } 38 | return boost::report_errors(); 39 | } 40 | -------------------------------------------------------------------------------- /shand/old/enable_if.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_ENABLE_IF_INCLUDE 2 | #define SHAND_ENABLE_IF_INCLUDE 3 | 4 | // Copyright 2003 (c) The Trustees of Indiana University. 5 | //// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu) 6 | // Jeremiah Willcock (jewillco at osl.iu.edu) 7 | // Andrew Lumsdaine (lums at osl.iu.edu) 8 | // 9 | // Copyright Akira Takahashi 2007 10 | // Use, modification and distribution is subject to the Boost Software License, 11 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 12 | // http://www.boost.org/LICENSE_1_0.txt) 13 | 14 | namespace shand { 15 | 16 | // enable_if 17 | template 18 | struct enable_if_c { 19 | typedef Type type; 20 | }; 21 | 22 | template 23 | struct enable_if_c {}; 24 | 25 | template 26 | struct enable_if : public enable_if_c {}; 27 | 28 | 29 | // disable_if 30 | template 31 | struct disable_if_c { 32 | typedef Type type; 33 | }; 34 | 35 | template 36 | struct disable_if_c {}; 37 | 38 | template 39 | struct disable_if : public disable_if_c {}; 40 | 41 | } // namespace shand 42 | 43 | #endif // SHAND_ENABLE_IF_INCLUDE 44 | -------------------------------------------------------------------------------- /libs/concurrent/example/queue.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Akira Takahashi 2015 2 | // Use, modification and distribution is subject to the Boost Software License, 3 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | void producer(shand::concurrent_queue& que) 11 | { 12 | for (int i = 0; i < 100; ++i) { 13 | que.push(i); 14 | } 15 | } 16 | 17 | void consumer(shand::concurrent_queue& que) 18 | { 19 | int i = 0; 20 | for (;;) { 21 | if (boost::optional x = que.pop()) { 22 | std::cout << x.get() << std::endl; 23 | ++i; 24 | } 25 | 26 | if (i > 30) 27 | return; 28 | } 29 | } 30 | 31 | int main() 32 | { 33 | shand::concurrent_queue que; 34 | 35 | std::thread t1(producer, std::ref(que)); 36 | std::thread t2(consumer, std::ref(que)); 37 | 38 | t1.join(); 39 | t2.join(); 40 | } 41 | 42 | /* 43 | output: 44 | 0 45 | 1 46 | 2 47 | 3 48 | 4 49 | 5 50 | 6 51 | 7 52 | 8 53 | 9 54 | 10 55 | 11 56 | 12 57 | 13 58 | 14 59 | 15 60 | 16 61 | 17 62 | 18 63 | 19 64 | 20 65 | 21 66 | 22 67 | 23 68 | 24 69 | 25 70 | 26 71 | 27 72 | 28 73 | 29 74 | 30 75 | */ 76 | 77 | -------------------------------------------------------------------------------- /shand/demangle_typename.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_DEMANGLE_TYPENAME_INCLUDE 2 | #define SHAND_DEMANGLE_TYPENAME_INCLUDE 3 | 4 | // demangle std::typeinfo::name() 5 | // 6 | // Copyright Akira Takahashi 2014 7 | // Use, modification and distribution is subject to the Boost Software License, 8 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 9 | // http://www.boost.org/LICENSE_1_0.txt) 10 | 11 | #include 12 | #include 13 | 14 | #if defined(BOOST_LIB_STD_GNU) || defined(BOOST_LIB_STD_CXX) 15 | #include 16 | #include // std::free 17 | #endif 18 | 19 | #include 20 | 21 | namespace shand { 22 | 23 | #if defined(BOOST_LIB_STD_GNU) || defined(BOOST_LIB_STD_CXX) 24 | template 25 | std::string demangle_typename() 26 | { 27 | int status = 0; 28 | char* demangled = abi::__cxa_demangle(typeid(T).name(), 0, 0, &status); 29 | 30 | BOOST_SCOPE_EXIT_TPL(demangled) { 31 | std::free(demangled); 32 | } BOOST_SCOPE_EXIT_END 33 | 34 | return std::string(demangled); 35 | } 36 | #else 37 | template 38 | std::string demangle_typename() 39 | { 40 | return typeid(T).name(); 41 | } 42 | #endif 43 | 44 | } // namespace shand 45 | 46 | #endif // SHAND_DEMANGLE_TYPENAME_INCLUDE 47 | 48 | -------------------------------------------------------------------------------- /libs/encoding_string/README.md: -------------------------------------------------------------------------------- 1 | # はじめに 2 | 3 | `encoding_string`は、文字コードのエンコーディング情報を持つ文字列クラスである。 4 | 5 | ## 選択可能な文字コード 6 | 7 | `encoding_string`クラスでは、以下の文字コードを選択可能だ。 8 | 9 | | 文字コード | 説明 | 10 | |--------------------|------| 11 | | UTF-16 | 16ビット(2バイト)で1文字を表現する。
後のUnicode領域の拡張により16ビットで全ての文字は表現できなくなった。そのため、稀に2文字分の領域を使用する「サロゲートペア(surrogate pair)」と呼ばれる種類の文字が現れることがある。
WindowsのUnicode APIはUTF-16を使用する。 | 12 | | UTF-8 | 複数バイトで1文字を表現する。
ASCII互換の文字コードで、ASCII部分(アルファベット、数字、少しの記号と制御文字)は1バイトかつASCIIのそれと同じビット列で表現する。ASCIIを越える部分は、1バイトから最大4バイトで1文字を表現する。
6バイト文字の領域も仕様上は存在するが、過去の他の文字コードとの互換性のためであり、現在は使われていない。 | 13 | | UTF-32 | 32ビット(4バイト)で1文字を表現する。
UTF-16とは違い、全ての文字が32ビット領域内で表現可能なため、サロゲートペアは存在しない。 | 14 | | システム文字コード | この文字コードは、標準出力の文字コードである。
たとえばWindowsのコマンドプロンプトは、デフォルト設定ではUTF-8文字コードの文字を出力できない。そのため、Windowsではシステム文字コードであるCP932(Shift_JISのMicrosoft拡張)に変換してから出力する必要がある。また、Microsoft Visual C++においては文字コード指定なしの文字列リテラルもまた、CP932である。
その他の環境において、システム文字コードはUTF-8としている。 | 15 | 16 | この表における文字コードの順番は、システム文字コードを除いて歴史順である。UTF-16が最も古く、UTF-32が最も新しい。 17 | 18 | 19 | ## 名前空間 20 | `encoding_string`、エンコーディングの種類、その他関数は、`shand`名前空間以下で定義される。 21 | 22 | 23 | ## ドキュメント目次 24 | 25 | - [基本的な使い方](doc/basic_usage.md) 26 | - [ビルド方法](doc/build.md) 27 | - [リファレンス](doc/reference.md) 28 | - 設計根拠 29 | - [将来の予定](doc/future_plan.md) 30 | 31 | 32 | -------------------------------------------------------------------------------- /shand/encoding_string/system_string.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_ENCODING_STRING_SYSTEM_INCLUDE 2 | #define SHAND_ENCODING_STRING_SYSTEM_INCLUDE 3 | 4 | // Copyright Akira Takahashi 2013 5 | // Use, modification and distribution is subject to the Boost Software License, 6 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | 11 | namespace shand { 12 | 13 | template <> 14 | class encoding_string { 15 | public: 16 | using string_type = std::basic_string; 17 | using value_type = std::basic_string; 18 | using cchar_type = char; 19 | 20 | encoding_string() {} 21 | encoding_string(const char* s) 22 | : data_(s) {} 23 | 24 | const cchar_type* c_str() const 25 | { return data_.c_str(); } 26 | 27 | const string_type& raw_str() const 28 | { return data_; } 29 | 30 | bool empty() const 31 | { return data_.empty(); } 32 | 33 | private: 34 | string_type data_; 35 | }; 36 | 37 | inline bool operator==(const encoding_string& a, const encoding_string& b) 38 | { return a.raw_str() == b.raw_str(); } 39 | 40 | inline bool operator!=(const encoding_string& a, const encoding_string& b) 41 | { return !(a == b); } 42 | 43 | } // namespace shand 44 | 45 | #endif // SHAND_ENCODING_STRING_SYSTEM_INCLUDE 46 | 47 | -------------------------------------------------------------------------------- /shand/lambda_return.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_LAMBDA_RETURN_INCLUDE 2 | #define SHAND_LAMBDA_RETURN_INCLUDE 3 | 4 | // Copyright Akira Takahashi 2014 5 | // Use, modification and distribution is subject to the Boost Software License, 6 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | namespace shand { 10 | 11 | class continuation_value { 12 | bool value_; 13 | public: 14 | explicit continuation_value(bool value) 15 | : value_(value) {} 16 | 17 | bool is_continue() const { return value_ == false; } 18 | bool is_break() const { return value_ == true; } 19 | }; 20 | 21 | namespace { 22 | const continuation_value continue_return(false); 23 | const continuation_value break_return(true); 24 | } 25 | 26 | } // namespace shand 27 | 28 | /* 29 | // example: 30 | 31 | template 32 | void my_for_each(Iterator first, Iterator last, F f) 33 | { 34 | for (; first != last; ++first) { 35 | if (f(*first).is_break()) { 36 | break; 37 | } 38 | } 39 | } 40 | 41 | #include 42 | #include 43 | int main() 44 | { 45 | std::vector v = {1, 2, 3}; 46 | 47 | my_for_each(v.begin(), v.end(), [](int x) { 48 | std::cout << x << std::endl; 49 | return shand::break_return; 50 | }); 51 | } 52 | */ 53 | 54 | #endif // SHAND_LAMBDA_RETURN_INCLUDE 55 | 56 | -------------------------------------------------------------------------------- /shand/old/lexical_cast.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_LEXICAL_CAST_INCLUDE 2 | #define SHAND_LEXICAL_CAST_INCLUDE 3 | 4 | // Copyright Kevlin Henney, 2000-2005. 5 | // Copyright Alexander Nasonov, 2006-2010. 6 | // Copyright Akira Takahashi 2007 7 | // Use, modification and distribution is subject to the Boost Software License, 8 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 9 | // http://www.boost.org/LICENSE_1_0.txt) 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | namespace shand { 16 | 17 | class bad_lexical_cast : public std::bad_cast 18 | { 19 | public: 20 | bad_lexical_cast(const std::string& what) 21 | : std::bad_cast(what.c_str()) {} 22 | }; 23 | 24 | 25 | template 26 | AfterType lexical_cast(const BeforeType& target) 27 | { 28 | AfterType result; 29 | std::stringstream interpreter; 30 | 31 | if (!(interpreter << target && interpreter >> result)) 32 | throw bad_lexical_cast("bad_lexical_cast"); 33 | 34 | return result; 35 | } 36 | 37 | template 38 | AfterType wlexical_cast(const BeforeType& target) 39 | { 40 | AfterType result; 41 | std::wstringstream interpreter; 42 | 43 | if (!(interpreter << target && interpreter >> result)) 44 | throw bad_lexical_cast("bad_lexical_cast"); 45 | 46 | return result; 47 | } 48 | 49 | } // namespace shand 50 | 51 | #endif // SHAND_LEXICAL_CAST_INCLUDE 52 | 53 | -------------------------------------------------------------------------------- /shand/strict_types/bool.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_STRICT_TYPES_BOOL_INCLUDE 2 | #define SHAND_STRICT_TYPES_BOOL_INCLUDE 3 | 4 | // disallow integer/floating point conversion bool 5 | // 6 | // Copyright Akira Takahashi 2013 7 | // Use, modification and distribution is subject to the Boost Software License, 8 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 9 | // http://www.boost.org/LICENSE_1_0.txt) 10 | 11 | #include 12 | #include 13 | 14 | namespace shand { 15 | 16 | class strict_bool : 17 | private boost::operators { 18 | bool value_; 19 | public: 20 | typedef bool value_type; 21 | 22 | strict_bool(bool value = false) 23 | : value_(value) {} 24 | 25 | template 26 | strict_bool(T) = delete; 27 | 28 | bool& get() { return value_; } 29 | const bool& get() const { return value_; } 30 | 31 | strict_bool& operator=(bool x) 32 | { 33 | value_ = x; 34 | return *this; 35 | } 36 | 37 | template 38 | strict_bool& operator=(T) = delete; 39 | 40 | // operators 41 | bool operator<(const strict_bool& x) const { return value_ < x.value_; } 42 | bool operator==(const strict_bool& x) const { return value_ == x.value_; } 43 | 44 | explicit operator bool() const 45 | { 46 | return value_; 47 | } 48 | }; 49 | 50 | } // namespace shand 51 | 52 | #endif // SHAND_STRICT_TYPES_BOOL_INCLUDE 53 | 54 | -------------------------------------------------------------------------------- /shand/fusion/adjacency_transform.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_FUSION_ADJACENCY_TRANSFORM_INCLUDE 2 | #define SHAND_FUSION_ADJACENCY_TRANSFORM_INCLUDE 3 | 4 | // Boost.Fusion extension. adjacency_transform algorithm. 5 | // 6 | // Copyright Akira Takahashi 2011 7 | // Use, modification and distribution is subject to the Boost Software License, 8 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 9 | // http://www.boost.org/LICENSE_1_0.txt) 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | namespace shand { namespace fusion { 16 | 17 | namespace result_of { 18 | 19 | template 20 | struct adjacency_transform { 21 | typedef 22 | typename boost::fusion::result_of::transform< 23 | boost::fusion::zip< 24 | Seq, 25 | typename boost::fusion::pop_front::type 26 | > 27 | F 28 | >::type 29 | type; 30 | }; 31 | 32 | } // namespace result_of 33 | 34 | template 35 | inline typename result_of::adjacency_transform::type 36 | adjacency_transform(const Seq& seq, F f) 37 | { 38 | namespace fusion = boost::fusion; 39 | return fusion::transform(fusion::zip(seq, fusion::pop_front(seq)), f); 40 | } 41 | 42 | }} // namespace shand::fusion 43 | 44 | #endif // SHAND_FUSION_ADJACENCY_TRANSFORM_INCLUDE 45 | 46 | -------------------------------------------------------------------------------- /shand/old/depend/singleton_holder.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Akira Takahashi 2006 2 | // Use, modification and distribution is subject to the Boost Software License, 3 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | 7 | #ifndef SINGLETON_HOLDER_INCLUDE 8 | #define SINGLETON_HOLDER_INCLUDE 9 | 10 | #include 11 | 12 | template 13 | class SingletonHolder { 14 | private: 15 | static Type* p_; 16 | static typename ThreadModel::AutoCriticalSection cs_; 17 | 18 | protected: 19 | SingletonHolder() { } 20 | 21 | public: 22 | static Type& Instance() 23 | { 24 | if (p_ == NULL) 25 | { 26 | cs_.Lock(); 27 | if (p_ == NULL) 28 | { 29 | try 30 | { 31 | p_ = new Type(); 32 | } 33 | catch (...) 34 | { 35 | cs_.Unlock(); 36 | throw; 37 | } 38 | } 39 | cs_.Unlock(); 40 | } 41 | return *p_; 42 | } 43 | }; 44 | 45 | template 46 | Type* SingletonHolder::p_ = NULL; 47 | template 48 | typename ThreadModel::AutoCriticalSection SingletonHolder::cs_; 49 | 50 | #endif // SINGLETON_HOLDER_INCLUDE 51 | 52 | -------------------------------------------------------------------------------- /shand/type_traits/is_callable.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_TYPE_TRAITS_IS_CALLABLE_INCLUDE 2 | #define SHAND_TYPE_TRAITS_IS_CALLABLE_INCLUDE 3 | 4 | // Copyright Mikael Persson 2011 5 | // Copyright Akira Takahashi 2015 6 | // Use, modification and distribution is subject to the Boost Software License, 7 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 8 | // http://www.boost.org/LICENSE_1_0.txt) 9 | // 10 | // Reference implementation is follow: 11 | // http://stackoverflow.com/questions/5100015/c-metafunction-to-determine-whether-a-type-is-callable/5100602#5100602 12 | #include 13 | #include 14 | 15 | namespace shand { 16 | 17 | namespace impl { 18 | 19 | template 20 | struct is_callable { 21 | typedef char (&no) [1]; 22 | typedef char (&yes) [2]; 23 | 24 | template struct dummy; 25 | 26 | template 27 | static yes check(dummy()(std::declval()...))> *); 28 | template 29 | static no check(...); 30 | 31 | static const bool value = sizeof(check(0)) == sizeof(yes); 32 | }; 33 | 34 | } // namespace impl 35 | 36 | template 37 | struct is_callable 38 | : std::integral_constant< 39 | bool, 40 | shand::impl::is_callable::value 41 | > {}; 42 | 43 | } // namespace shand 44 | 45 | #endif // SHAND_TYPE_TRAITS_IS_CALLABLE_INCLUDE 46 | 47 | -------------------------------------------------------------------------------- /libs/callback_promise/io_service.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Akira Takahashi 2013. 2 | // Use, modification and distribution is subject to the Boost Software License, 3 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | // Not good sample. 12 | // This case can use `function` instead of `callback_promise`. 13 | class io_service { 14 | std::list> callback_queue_; 15 | shand::callback_promise promise_; 16 | public: 17 | template 18 | io_service& post(F f) 19 | { 20 | promise_.set_callback(f); 21 | return *this; 22 | } 23 | 24 | template 25 | io_service& then(F f) 26 | { 27 | callback_queue_.push_back(f); 28 | return *this; 29 | } 30 | 31 | void run() 32 | { 33 | while (!callback_queue_.empty()) { 34 | promise_.set_value(); 35 | promise_.clear(); 36 | callback_queue_.front()(); 37 | callback_queue_.pop_front(); 38 | } 39 | } 40 | }; 41 | 42 | void f1() { std::cout << 0 << std::endl; } 43 | void f2() { std::cout << 1 << std::endl; } 44 | void f3() { std::cout << 2 << std::endl; } 45 | 46 | int main() 47 | { 48 | io_service ios; 49 | 50 | ios.post(f1) 51 | .then([&] { ios.post(f2); }) 52 | .then([&] { ios.post(f3); }) 53 | .then([]{}); 54 | 55 | ios.run(); 56 | } 57 | -------------------------------------------------------------------------------- /shand/optional_algorithm/find_if.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_OPTIONAL_ALGORITHM_FIND_IF_INCLUDE 2 | #define SHAND_OPTIONAL_ALGORITHM_FIND_IF_INCLUDE 3 | 4 | // Shand Optional Algorithm Library 5 | // 6 | // Copyright Akira Takahashi 2011 7 | // Use, modification and distribution is subject to the Boost Software License, 8 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 9 | // http://www.boost.org/LICENSE_1_0.txt) 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | namespace shand { namespace optional_algorithm { 16 | 17 | template 18 | inline boost::optional::type> 19 | find_if(SinglePassRange& r, UnaryPredicate pred) 20 | { 21 | typename boost::range_iterator::type it = boost::find_if(r, pred); 22 | if (it != boost::end(r)) { 23 | return *it; 24 | } 25 | return boost::none; 26 | } 27 | 28 | template 29 | inline boost::optional::type> 30 | find_if(const SinglePassRange& r, UnaryPredicate pred) 31 | { 32 | typename boost::range_iterator::type it = boost::find_if(r, pred); 33 | if (it != boost::end(r)) { 34 | return *it; 35 | } 36 | return boost::none; 37 | } 38 | 39 | } // namespace optional_algorithm 40 | 41 | using optional_algorithm::find_if; 42 | 43 | } // namespace shand 44 | 45 | 46 | #endif // SHAND_OPTIONAL_ALGORITHM_FIND_IF_INCLUDE 47 | 48 | -------------------------------------------------------------------------------- /libs/graph/euler_path/santa_house.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Akira Takahashi 2012 2 | // Use, modification and distribution is subject to the Boost Software License, 3 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | enum {A, B, C, D, E, N}; 13 | const std::string name = "ABCDE"; 14 | 15 | int main() 16 | { 17 | typedef boost::adjacency_list Graph; 18 | typedef boost::graph_traits::vertex_descriptor vertex_desc; 19 | 20 | // House of Santa : http://ameblo.jp/masanori432/entry-10058793629.html 21 | // path variation : http://www.mathematische-basteleien.de/house.html 22 | const std::vector > edges = { 23 | {A, B}, 24 | {B, C}, 25 | {C, A}, 26 | {B, D}, 27 | {B, E}, 28 | {C, D}, 29 | {D, E}, 30 | {E, C} 31 | }; 32 | 33 | const Graph g(edges.begin(), edges.end(), N); 34 | std::deque path; 35 | 36 | if (!shand::graph::euler_path(g, vertex(E, g), [&path] (vertex_desc v) { path.push_front(v); })) { 37 | std::cout << "euler path failed" << std::endl; 38 | return 1; 39 | } 40 | 41 | BOOST_FOREACH (const vertex_desc& v, path) { 42 | std::cout << name[get(boost::vertex_index, g, v)] << std::endl; 43 | } 44 | } 45 | 46 | /* 47 | output: 48 | E 49 | B 50 | A 51 | C 52 | B 53 | D 54 | C 55 | E 56 | D 57 | 58 | */ 59 | 60 | -------------------------------------------------------------------------------- /shand/old/depend/message_box.h: -------------------------------------------------------------------------------- 1 | // Copyright Akira Takahashi 2006 2 | // Use, modification and distribution is subject to the Boost Software License, 3 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | 7 | // ※ Windows用 8 | //------------------------------------------------------// 9 | // Name : simple_message_box // 10 | // Desc : 簡易メッセージボックス // 11 | // Note : 整数、小数表示用 // 12 | // // 13 | // Version : 1.00 2006/08/04 作成 // 14 | // 1.01 2006/12/14 Unicodeに対応 // 15 | // // 16 | // Programmed By Akira.T // 17 | // Copyright(C) 2006 Akira.T All rights reserved // 18 | // // 19 | //------------------------------------------------------// 20 | 21 | #ifndef _SHAND_MESSAGEBOX_H_ 22 | #define _SHAND_MESSAGEBOX_H_ 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | template 29 | inline void simple_message_box(const Type& msg) 30 | { 31 | std::basic_stringstream interpreter; 32 | 33 | interpreter << msg; 34 | MessageBox(NULL, interpreter.str().c_str(), _T(""), MB_OK); 35 | } 36 | 37 | #endif // _SHAND_MESSAGEBOX_H_ 38 | 39 | //------------------------------------------| 40 | // How to use | 41 | //------------------------------------------| 42 | // | 43 | // int n = 314; | 44 | // simple_message_box(n); | 45 | // | 46 | // double f = 3.14; | 47 | // simple_message_box(f); | 48 | // | 49 | // string s = "abc" | 50 | // simple_message_box(s); | 51 | // | 52 | //------------------------------------------| 53 | -------------------------------------------------------------------------------- /libs/strong_typedef/tagged_float_example.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Akira Takahashi 2012 2 | // Use, modification and distribution is subject to the Boost Software License, 3 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | struct degree_tag {}; 11 | struct radian_tag {}; 12 | 13 | template 14 | using degree = shand::tagged_float; 15 | 16 | template 17 | using radian = shand::tagged_float; 18 | 19 | template 20 | radian degree_to_radian(const degree& x) 21 | { 22 | return radian(x.get() * boost::math::constants::pi() / static_cast(180.0)); 23 | } 24 | 25 | template 26 | degree radian_to_degree(const radian& x) 27 | { 28 | return degree(x.get() * static_cast(180.0) / boost::math::constants::pi()); 29 | } 30 | 31 | int main () 32 | { 33 | // 異なる型(タグ)間での暗黙変換はできない 34 | { 35 | degree deg(90.0f); 36 | // radian rad = deg; // コンパイルエラー!型が違う 37 | } 38 | 39 | // degreeからradianへの変換 40 | { 41 | degree deg(90.0f); 42 | radian rad = degree_to_radian(deg); 43 | std::cout << rad << std::endl; 44 | } 45 | 46 | // radianからdegreeへの変換 47 | { 48 | radian rad(0.5 * boost::math::constants::pi()); 49 | degree deg = radian_to_degree(rad); 50 | std::cout << deg << std::endl; 51 | } 52 | } 53 | 54 | /* 55 | output: 56 | 1.5708 57 | 90 58 | */ 59 | 60 | -------------------------------------------------------------------------------- /shand/io_adaptor/io.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_IO_ADAPTOR_IO_HPP 2 | #define SHAND_IO_ADAPTOR_IO_HPP 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "./traits.hpp" 9 | 10 | namespace shand { namespace io_adaptors { 11 | 12 | template 13 | inline void out(std::ostream& os, const Seq& seq); 14 | 15 | template 16 | inline void out_detail(std::ostream& os, const T& x, none_tag) 17 | { 18 | os << x; 19 | } 20 | 21 | template 22 | inline void out_detail(std::ostream& os, const Seq& seq, range_tag) 23 | { 24 | out(os, '{'); 25 | 26 | typedef typename boost::range_iterator::type iterator; 27 | iterator first = boost::begin(seq); 28 | iterator last = boost::end(seq); 29 | 30 | bool is_beginning = true; 31 | for (; first != last; ++first) { 32 | if (!is_beginning) 33 | out(os, ','); 34 | else 35 | is_beginning = false; 36 | 37 | out(os, *first); 38 | } 39 | 40 | out(os, '}'); 41 | } 42 | 43 | template 44 | inline void out(std::ostream& os, const Seq& seq) 45 | { 46 | out_detail(os, seq, typename tag_of::type()); 47 | } 48 | 49 | namespace operators { 50 | 51 | template 52 | inline typename boost::enable_if< 53 | is_adapted, 54 | std::ostream& 55 | >::type operator<<(std::ostream& os, const Seq& seq) 56 | { 57 | io_adaptors::out(os, seq); 58 | return os; 59 | } 60 | 61 | } // namespace operators 62 | 63 | }} // namespace shand::io_adaptors 64 | 65 | #endif // SHAND_IO_ADAPTOR_IO_HPP 66 | 67 | -------------------------------------------------------------------------------- /libs/graph/euler_path/test_has_euler_path.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Akira Takahashi 2012 2 | // Use, modification and distribution is subject to the Boost Software License, 3 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | // A 12 | // + 13 | // - - 14 | // B +---------+ C 15 | // | - - | 16 | // | + | 17 | // | - - | 18 | // D +---------+ E 19 | 20 | int main() 21 | { 22 | typedef boost::adjacency_list Graph; 23 | 24 | enum {A, B, C, D, E, N}; 25 | 26 | // House of Santa 27 | // http://www.mathematische-basteleien.de/house.html 28 | const std::vector > edges = boost::assign::list_of 29 | (std::make_pair(A, B)) 30 | (std::make_pair(B, C)) 31 | (std::make_pair(C, A)) 32 | (std::make_pair(B, D)) 33 | (std::make_pair(B, E)) 34 | (std::make_pair(C, D)) 35 | (std::make_pair(D, E)) 36 | (std::make_pair(E, C)) 37 | ; 38 | 39 | const Graph g(edges.begin(), edges.end(), N); 40 | 41 | BOOST_TEST(!shand::graph::has_euler_path(g, vertex(A, g))); 42 | BOOST_TEST(!shand::graph::has_euler_path(g, vertex(B, g))); 43 | BOOST_TEST(!shand::graph::has_euler_path(g, vertex(C, g))); 44 | 45 | BOOST_TEST(shand::graph::has_euler_path(g, vertex(D, g))); 46 | BOOST_TEST(shand::graph::has_euler_path(g, vertex(E, g))); 47 | 48 | return boost::report_errors(); 49 | } 50 | 51 | -------------------------------------------------------------------------------- /libs/errorable/example.cpp: -------------------------------------------------------------------------------- 1 | // Shand C++ Library 2 | // 3 | // Copyright Akira Takahashi 2013 4 | // Use, modification and distribution is subject to the Boost Software License, 5 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | int main() 13 | { 14 | // 初期状態はエラー 15 | { 16 | shand::errorable x; 17 | BOOST_ASSERT(x.is_error()); 18 | } 19 | 20 | // エラーが発生しているケース 21 | // エラー理由を格納する 22 | // デフォルトのエラー型はstd::string 23 | { 24 | shand::errorable value = shand::error("invalid argument"); 25 | if (boost::optional err = value.get_error()) { 26 | std::cout << err.get() << std::endl; 27 | } 28 | } 29 | 30 | // 正常な値が入っているケース 31 | { 32 | shand::errorable value = 3; 33 | if (boost::optional x = value.get_value()) { 34 | std::cout << x.get() << std::endl; 35 | } 36 | } 37 | 38 | // 値が正常かエラーかによって、関数を呼び分ける 39 | { 40 | shand::errorable value = shand::error("invalid argument"); 41 | value.value_if([](int x) { 42 | std::cout << x << std::endl; 43 | }) 44 | .error_if([](const std::string& err) { 45 | std::cout << err << std::endl; 46 | }); 47 | } 48 | 49 | // 第2テンプレート引数で、エラー型をカスタマイズ可能 50 | { 51 | shand::errorable value = shand::error(std::errc::invalid_argument); 52 | if (boost::optional err = value.get_error()) { 53 | std::cout << std::make_error_code(err.get()).message() << std::endl; 54 | } 55 | } 56 | } 57 | 58 | -------------------------------------------------------------------------------- /libs/encoding_string/encode_test.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Akira Takahashi 2013 2 | // Use, modification and distribution is subject to the Boost Software License, 3 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | using shand::encoding_string; 11 | namespace encoding = shand::encoding; 12 | 13 | template 14 | void test(FromValue from_literal, ToValue to_literal) 15 | { 16 | const encoding_string from = from_literal; 17 | const encoding_string to = shand::encode(from); 18 | 19 | BOOST_TEST(to == encoding_string(to_literal)); 20 | } 21 | 22 | int main() 23 | { 24 | const char utf8[] = u8"あいうえお"; 25 | const char16_t utf16[] = u"あいうえお"; 26 | const char32_t utf32[] = U"あいうえお"; 27 | const char sys[] = "あいうえお"; 28 | 29 | test(utf8, utf8); 30 | test(utf8, utf16); 31 | test(utf8, utf32); 32 | test(utf8, sys); 33 | 34 | test(utf16, utf8); 35 | test(utf16, utf16); 36 | test(utf16, utf32); 37 | test(utf16, sys); 38 | 39 | test(utf32, utf8); 40 | test(utf32, utf16); 41 | test(utf32, utf32); 42 | test(utf32, sys); 43 | 44 | return boost::report_errors(); 45 | } 46 | 47 | -------------------------------------------------------------------------------- /shand/duration.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_DURATION_INCLUDE 2 | #define SHAND_DURATION_INCLUDE 3 | 4 | // Copyright Akira Takahashi 2014 5 | // Use, modification and distribution is subject to the Boost Software License, 6 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | 11 | namespace shand { 12 | 13 | template 14 | using nanoseconds_t = std::chrono::duration; 15 | using nanoseconds_f = nanoseconds_t; 16 | using nanoseconds_d = nanoseconds_t; 17 | using nanoseconds_ld = nanoseconds_t; 18 | 19 | template 20 | using microseconds_t = std::chrono::duration; 21 | using microseconds_f = microseconds_t; 22 | using microseconds_d = microseconds_t; 23 | using microseconds_ld = microseconds_t; 24 | 25 | template 26 | using milliseconds_t = std::chrono::duration; 27 | using milliseconds_f = milliseconds_t; 28 | using milliseconds_d = milliseconds_t; 29 | using milliseconds_ld = milliseconds_t; 30 | 31 | template 32 | using seconds_t = std::chrono::duration; 33 | using seconds_f = seconds_t; 34 | using seconds_d = seconds_t; 35 | using seconds_ld = seconds_t; 36 | 37 | template 38 | using minutes_t = std::chrono::duration>; 39 | using minutes_f = minutes_t; 40 | using minutes_d = minutes_t; 41 | using minutes_ld = minutes_t; 42 | 43 | template 44 | using hours_t = std::chrono::duration>; 45 | using hours_f = hours_t; 46 | using hours_d = hours_t; 47 | using hours_ld = hours_t; 48 | 49 | } // namespace shand 50 | 51 | #endif // SHAND_DURATION_INCLUDE 52 | 53 | -------------------------------------------------------------------------------- /libs/callback_promise/test.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Akira Takahashi 2013. 2 | // Use, modification and distribution is subject to the Boost Software License, 3 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | #include 8 | 9 | struct IntCallOrder { 10 | static void callback_value_test() 11 | { 12 | int result = 0; 13 | shand::callback_promise p; 14 | 15 | p.set_callback([&](int value) { 16 | result = value; 17 | }); 18 | p.set_value(3); 19 | 20 | BOOST_TEST(result == 3); 21 | } 22 | 23 | static void value_callback_test() 24 | { 25 | int result = 0; 26 | shand::callback_promise p; 27 | 28 | p.set_value(3); 29 | p.set_callback([&](int value) { 30 | result = value; 31 | }); 32 | 33 | BOOST_TEST(result == 3); 34 | } 35 | }; 36 | 37 | struct VoidCallOrder { 38 | static void callback_value_test() 39 | { 40 | bool is_called = false; 41 | shand::callback_promise p; 42 | 43 | p.set_callback([&] { 44 | is_called = true; 45 | }); 46 | p.set_value(); 47 | 48 | BOOST_TEST(is_called); 49 | } 50 | 51 | static void value_callback_test() 52 | { 53 | bool is_called = false; 54 | shand::callback_promise p; 55 | 56 | p.set_value(); 57 | p.set_callback([&] { 58 | is_called = true; 59 | }); 60 | 61 | BOOST_TEST(is_called); 62 | } 63 | }; 64 | 65 | int main() 66 | { 67 | IntCallOrder::callback_value_test(); 68 | IntCallOrder::value_callback_test(); 69 | 70 | VoidCallOrder::callback_value_test(); 71 | VoidCallOrder::value_callback_test(); 72 | 73 | return boost::report_errors(); 74 | } 75 | -------------------------------------------------------------------------------- /shand/callback_promise.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_CALLBACK_PROMISE_INCLUDE 2 | #define SHAND_CALLBACK_PROMISE_INCLUDE 3 | 4 | // Callback promise class. (single thread only yet) 5 | // 6 | // Copyright Akira Takahashi 2013 7 | // Use, modification and distribution is subject to the Boost Software License, 8 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 9 | // http://www.boost.org/LICENSE_1_0.txt) 10 | 11 | #include 12 | #include 13 | 14 | namespace shand { 15 | 16 | template 17 | class callback_promise { 18 | boost::optional value_; 19 | boost::function callback_; 20 | public: 21 | void set_value(const R& value) 22 | { 23 | value_ = value; 24 | if (callback_) { 25 | callback_(value); 26 | } 27 | } 28 | 29 | template 30 | void set_callback(F callback) 31 | { 32 | callback_ = callback; 33 | if (value_) { 34 | callback_(value_.get()); 35 | } 36 | } 37 | 38 | void clear() 39 | { 40 | value_ = boost::none; 41 | callback_.clear(); 42 | } 43 | }; 44 | 45 | template <> 46 | class callback_promise { 47 | bool has_value_; 48 | boost::function callback_; 49 | public: 50 | callback_promise() 51 | : has_value_(false) {} 52 | 53 | void set_value() 54 | { 55 | has_value_ = true; 56 | if (callback_) { 57 | callback_(); 58 | } 59 | } 60 | 61 | template 62 | void set_callback(F callback) 63 | { 64 | callback_ = callback; 65 | if (has_value_) { 66 | callback_(); 67 | } 68 | } 69 | 70 | void clear() 71 | { 72 | has_value_ = false; 73 | callback_.clear(); 74 | } 75 | }; 76 | 77 | } // namespace shand 78 | 79 | #endif // SHAND_CALLBACK_PROMISE_INCLUDE 80 | 81 | -------------------------------------------------------------------------------- /shand/strict_types/real.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_STRICT_TYPES_REAL_INCLUDE 2 | #define SHAND_STRICT_TYPES_REAL_INCLUDE 3 | 4 | // disallow bool conversion floating point 5 | // 6 | // Copyright Akira Takahashi 2013 7 | // Use, modification and distribution is subject to the Boost Software License, 8 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 9 | // http://www.boost.org/LICENSE_1_0.txt) 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | namespace shand { 16 | 17 | template 18 | class strict_real : 19 | private boost::operators> { 20 | static_assert(std::is_floating_point{}, "T should floating point type"); 21 | static_assert(!std::is_same{}, "T shouldn't bool type"); 22 | 23 | T value_; 24 | public: 25 | typedef T value_type; 26 | 27 | strict_real(bool) = delete; 28 | strict_real(T value = 0) : value_(value) {} 29 | 30 | T& get() { return value_; } 31 | const T& get() const { return value_; } 32 | 33 | strict_real& operator=(bool) = delete; 34 | strict_real& operator=(T x) 35 | { 36 | value_ = x; 37 | return *this; 38 | } 39 | 40 | // operators 41 | bool operator<(const strict_real& x) const { return value_ < x.value_; } 42 | strict_real& operator+=(const strict_real& x) { value_ += x.value_; return *this; } 43 | strict_real& operator-=(const strict_real& x) { value_ -= x.value_; return *this; } 44 | strict_real& operator*=(const strict_real& x) { value_ *= x.value_; return *this; } 45 | strict_real& operator/=(const strict_real& x) { value_ /= x.value_; return *this; } 46 | strict_real& operator%=(const strict_real& x) { value_ %= x.value_; return *this; } 47 | 48 | bool equals(const strict_real& x) const 49 | { 50 | return boost::geometry::math::equals(value_, x.value_); 51 | } 52 | }; 53 | 54 | } // namespace shand 55 | 56 | #endif // SHAND_STRICT_TYPES_REAL_INCLUDE 57 | 58 | -------------------------------------------------------------------------------- /shand/round.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_ROUND_INCLUDE 2 | #define SHAND_ROUND_INCLUDE 3 | 4 | // Round utilities. 5 | // 6 | // Copyright Akira Takahashi 2013 7 | // Use, modification and distribution is subject to the Boost Software License, 8 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 9 | // http://www.boost.org/LICENSE_1_0.txt) 10 | 11 | #include 12 | #include 13 | 14 | namespace shand { 15 | 16 | template 17 | To ceil_to(From x) 18 | { 19 | static_assert(std::is_floating_point::value, 20 | "from type must be floating point type"); 21 | 22 | return static_cast(std::ceil(x)); 23 | } 24 | 25 | template 26 | To floor_to(From x) 27 | { 28 | static_assert(std::is_floating_point::value, 29 | "from type must be floating point type"); 30 | 31 | return static_cast(std::floor(x)); 32 | } 33 | 34 | 35 | // round to the nearest integer value 36 | template 37 | To round_to(From x) 38 | { 39 | static_assert(std::is_floating_point::value, 40 | "from type must be floating point type"); 41 | 42 | return static_cast(std::round(x)); 43 | } 44 | 45 | // round to the nearest even 46 | // a.k.a. banker's rounding 47 | // 48 | // reference implementation: 49 | // http://home.roadrunner.com/~hinnant/duration_io/chrono_util.html 50 | template 51 | To round_even_to(From x) 52 | { 53 | static_assert(std::is_floating_point::value, 54 | "from type must be floating point type"); 55 | 56 | To t0 = floor_to(x); 57 | To t1 = t0; 58 | 59 | ++t1; 60 | 61 | auto diff0 = x - t0; 62 | auto diff1 = t1 - x; 63 | if (diff0 == diff1) 64 | { 65 | if (t0 & 1) 66 | return t1; 67 | return t0; 68 | } 69 | else if (diff0 < diff1) 70 | return t0; 71 | return t1; 72 | } 73 | 74 | } // namespace shand 75 | 76 | #endif // SHAND_ROUND_INCLUDE 77 | 78 | -------------------------------------------------------------------------------- /shand/old/depend/date_time.h: -------------------------------------------------------------------------------- 1 | #ifndef _DATETIME_H_ 2 | #define _DATETIME_H_ 3 | 4 | // Copyright Akira Takahashi 2007 5 | // Use, modification and distribution is subject to the Boost Software License, 6 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include "cstring_format.h" 10 | 11 | 12 | //----------------------------------------------// 13 | // 名称 : GetDateTimeString() // 14 | // 用途 : フォーマット指定した日時文字列取得 // 15 | // 引数 : strFormat : 日時フォーマット // 16 | // %Y : 年 YYYY // 17 | // %m : 月 mm // 18 | // %D : 日 DD // 19 | // %H : 時 HH // 20 | // %M : 分 MM // 21 | // %S : 秒 SS // 22 | // tmDateTime: 指定時間(未指定は現在日時)// 23 | // 戻値 : 日時文字列 // 24 | // メモ : WinCEでCOleDateTime::Format(...)が // 25 | // 未サポートのため作成 // 26 | //----------------------------------------------// 27 | inline CString GetDateTimeString(CString strFormat, 28 | const COleDateTime &tmDateTime=COleDateTime::GetCurrentTime()) 29 | { 30 | strFormat.Replace(_T("%Y"), FormatString(_T("%04d"), tmDateTime.GetYear())); 31 | strFormat.Replace(_T("%m"), FormatString(_T("%02d"), tmDateTime.GetMonth())); 32 | strFormat.Replace(_T("%D"), FormatString(_T("%02d"), tmDateTime.GetDay())); 33 | strFormat.Replace(_T("%d"), FormatString(_T("%02d"), tmDateTime.GetDay())); 34 | strFormat.Replace(_T("%H"), FormatString(_T("%02d"), tmDateTime.GetHour())); 35 | strFormat.Replace(_T("%M"), FormatString(_T("%02d"), tmDateTime.GetMinute())); 36 | strFormat.Replace(_T("%S"), FormatString(_T("%02d"), tmDateTime.GetSecond())); 37 | return strFormat; 38 | } 39 | 40 | 41 | /*----------------------------------------------| 42 | | How to use | 43 | |-----------------------------------------------| 44 | | | 45 | | SetWindowText(GetDateTimeString("%Y/%m/%D")); | 46 | | | 47 | | |---------------------------| | 48 | | | 2006/01/01 | | 49 | | |---------------------------| | 50 | | | 51 | |----------------------------------------------*/ 52 | 53 | 54 | #endif // _DATETIME_H_ 55 | -------------------------------------------------------------------------------- /shand/fusion/copy.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_FUSION_COPY_INCLUDE 2 | #define SHAND_FUSION_COPY_INCLUDE 3 | 4 | // Shand, Boost.Fusion extended library 5 | // 6 | // Copyright Akira Takahashi 2011 7 | // Use, modification and distribution is subject to the Boost Software License, 8 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 9 | // http://www.boost.org/LICENSE_1_0.txt) 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | namespace shand { namespace fusion { 18 | 19 | template 20 | void copy_impl(IIteratorFirst ifirst, IIteratorLast ilast, OIteratorFirst result, boost::mpl::true_) 21 | { 22 | } 23 | 24 | template 25 | void copy_impl(IIteratorFirst ifirst, IIteratorLast ilast, OIteratorFirst result, boost::mpl::false_) 26 | { 27 | namespace fusion = boost::fusion; 28 | 29 | *result = *ifirst; 30 | 31 | copy_impl(fusion::next(ifirst), ilast, fusion::next(result), 32 | fusion::result_of::equal_to< 33 | typename fusion::result_of::next::type, 34 | IIteratorLast 35 | >()); 36 | } 37 | 38 | template 39 | void copy(const InputSequence& input, OutputSequence& output) 40 | { 41 | namespace fusion = boost::fusion; 42 | 43 | BOOST_STATIC_ASSERT(fusion::result_of::size::value == 44 | fusion::result_of::size::value); 45 | 46 | copy_impl(fusion::begin(input), fusion::end(input), fusion::begin(output), 47 | fusion::result_of::equal_to< 48 | typename fusion::result_of::begin::type, 49 | typename fusion::result_of::end::type 50 | >()); 51 | } 52 | 53 | }} // namespace shand::fusion 54 | 55 | #endif // SHAND_FUSION_COPY_INCLUDE 56 | 57 | -------------------------------------------------------------------------------- /shand/old/depend/tray_icon.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Akira Takahashi 2006 2 | // Use, modification and distribution is subject to the Boost Software License, 3 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #ifndef _CE_TRAY_ICON_HPP_ 7 | #define _CE_TRAY_ICON_HPP_ 8 | 9 | #define WM_TRAY_ICON 0x1000 10 | 11 | // ※MFC用 12 | 13 | //==============================// 14 | // // 15 | // トレイアイコン管理クラス // 16 | // // 17 | //==============================// 18 | class CTrayIcon { 19 | public: 20 | explicit CTrayIcon() {} 21 | 22 | ~CTrayIcon() 23 | { 24 | Hide(); 25 | } 26 | 27 | //--------------------------// 28 | // アイコン作成 // 29 | // OnInitDialog()で実行 // 30 | //--------------------------// 31 | void Create(HWND hWnd, UINT nIconID) 32 | { 33 | m_stTrayIcon.cbSize = sizeof(NOTIFYICONDATA); 34 | m_stTrayIcon.uID = 0; 35 | m_stTrayIcon.hWnd = hWnd; 36 | m_stTrayIcon.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP; 37 | m_stTrayIcon.hIcon = (HICON)LoadImage(AfxGetResourceHandle(), 38 | MAKEINTRESOURCE(nIconID), 39 | IMAGE_ICON, 40 | 16, 16, 41 | LR_DEFAULTCOLOR); 42 | m_stTrayIcon.uCallbackMessage = WM_TRAY_ICON; 43 | lstrcpy(m_stTrayIcon.szTip, _T("Tray")); 44 | } 45 | 46 | //--------------------------// 47 | // アイコン表示 // 48 | //--------------------------// 49 | void Show() 50 | { 51 | Shell_NotifyIcon(NIM_ADD, &m_stTrayIcon); 52 | } 53 | 54 | //--------------------------// 55 | // アイコン非表示 // 56 | //--------------------------// 57 | void Hide() 58 | { 59 | Shell_NotifyIcon(NIM_DELETE, &m_stTrayIcon); 60 | } 61 | 62 | //--------------------------// 63 | // アイコン切替 // 64 | //--------------------------// 65 | void Modify(UINT nIconID) 66 | { 67 | m_stTrayIcon.hIcon = (HICON)LoadImage(AfxGetResourceHandle(), 68 | MAKEINTRESOURCE(nIconID), 69 | IMAGE_ICON, 70 | 16, 16, 71 | LR_DEFAULTCOLOR); 72 | Shell_NotifyIcon(NIM_MODIFY, &m_stTrayIcon); 73 | } 74 | 75 | private: 76 | NOTIFYICONDATA m_stTrayIcon; // トレイアイコン 77 | }; 78 | 79 | #endif // _CE_TRAY_ICON_HPP_ 80 | -------------------------------------------------------------------------------- /shand/old/depend/elapsed_time.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Akira Takahashi 2006 2 | // Use, modification and distribution is subject to the Boost Software License, 3 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | // ※ Windows用 7 | 8 | //------------------------------------------------------// 9 | // Name : CElapsedTime // 10 | // Desc : 経過時間測定クラス // 11 | // // 12 | // Version : 1.00 2006/08/01 作成 // 13 | // 1.01 2006/12/14 Unicodeに対応 // 14 | // // 15 | //------------------------------------------------------// 16 | 17 | #ifndef _ELAPSED_TIME_HPP_ 18 | #define _ELAPSED_TIME_HPP_ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | // 経過時間測定クラス 25 | class CElapsedTime { 26 | private: 27 | DWORD m_dwStartTime; // 開始時間 28 | public: 29 | CElapsedTime() 30 | : m_dwStartTime(GetTickCount()) 31 | { 32 | } 33 | 34 | ~CElapsedTime() {}; 35 | 36 | void ReStart() 37 | { 38 | m_dwStartTime = GetTickCount(); 39 | } 40 | 41 | // 経過時間取得 42 | double GetElapsedTime() const 43 | { 44 | return static_cast(GetTickCount() - m_dwStartTime)/1000; 45 | } 46 | 47 | // 経過時間表示 48 | void DispElapsedTime() 49 | { 50 | std::basic_ostringstream strTime; 51 | strTime << GetElapsedTime() << _T("秒"); 52 | MessageBox(NULL, strTime.str().c_str(), _T("ElapsedTime"), MB_OK); 53 | } 54 | }; 55 | 56 | #endif //_ELAPSED_TIME_HPP_ 57 | 58 | //-----使用例-----------------------------------| 59 | // | 60 | // CElapedTime tmElapsed; // 経過時間 | 61 | // | 62 | // 〜〜〜時間のかかる処理〜〜〜 | 63 | // | 64 | // // 経過時間をポップアップ表示 | 65 | // tmElapsed.DispElapsedTime(); | 66 | // | 67 | //----------------------------------------------| 68 | 69 | //-----使用例-----------------------------------| 70 | // | 71 | // CElapedTime tmElapsed; // 経過時間 | 72 | // | 73 | // 〜〜〜時間のかかる処理〜〜〜 | 74 | // | 75 | // // 経過時間取得 | 76 | // 〜〜 = tmElapsed.GetElapsedTime(); | 77 | // | 78 | // 〜〜経過時間を使った処理 | 79 | // | 80 | //----------------------------------------------| 81 | -------------------------------------------------------------------------------- /shand/concurrent/queue.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_CONCURRENT_QUEUE_INCLUDE 2 | #define SHAND_CONCURRENT_QUEUE_INCLUDE 3 | 4 | // Copyright Akira Takahashi 2015 5 | // Use, modification and distribution is subject to the Boost Software License, 6 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | namespace shand { 16 | 17 | template 18 | class concurrent_queue { 19 | // If this requirement is true, optional(T&&) also nothrow (by document 1.57.0) 20 | static_assert( 21 | std::is_nothrow_move_constructible::value, 22 | "Type T must be nothrow move constructible"); 23 | 24 | std::deque que_; 25 | mutable std::shared_timed_mutex mutex_; 26 | public: 27 | concurrent_queue() {} 28 | 29 | concurrent_queue(const concurrent_queue&) = delete; 30 | concurrent_queue& operator=(const concurrent_queue&) = delete; 31 | 32 | // write access 33 | void push(const T& x) 34 | { 35 | std::lock_guard lock(mutex_); 36 | que_.push_back(x); 37 | } 38 | 39 | void push(T&& x) 40 | { 41 | std::lock_guard lock(mutex_); 42 | que_.push_back(std::move(x)); 43 | } 44 | 45 | boost::optional pop() noexcept 46 | { 47 | std::lock_guard lock(mutex_); 48 | if (que_.empty()) 49 | return boost::none; 50 | 51 | T front = std::move(que_.front()); 52 | que_.pop_front(); 53 | return front; 54 | } 55 | 56 | void clear() 57 | { 58 | std::lock_guard lock(mutex_); 59 | que_.clear(); 60 | } 61 | 62 | // read access 63 | std::size_t size() const 64 | { 65 | std::shared_lock lock(mutex_); 66 | return que_.size(); 67 | } 68 | 69 | bool empty() const 70 | { 71 | std::shared_lock lock(mutex_); 72 | return que_.empty(); 73 | } 74 | }; 75 | 76 | } // namespace shand 77 | 78 | #endif // SHAND_CONCURRENT_QUEUE_INCLUDE 79 | 80 | -------------------------------------------------------------------------------- /libs/special_value/test/test.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Akira Takahashi 2014 2 | // Use, modification and distribution is subject to the Boost Software License, 3 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | enum class E { e }; 16 | 17 | template 18 | std::pair call(SpecialValue& value) 19 | { 20 | using MutableSpecialValue = typename std::remove_const::type; 21 | 22 | bool is_call_on_value = false; 23 | bool is_call_on_enum = false; 24 | value.on_value([&is_call_on_value](typename MutableSpecialValue::value_type x) { 25 | static_cast(x); 26 | is_call_on_value = true; 27 | }) 28 | .on_enum([&is_call_on_enum](typename MutableSpecialValue::enum_type e) { 29 | static_cast(e); 30 | is_call_on_enum = true; 31 | }); 32 | return std::make_pair(is_call_on_value, is_call_on_enum); 33 | } 34 | 35 | template 36 | void value_test(T x) 37 | { 38 | shand::special_value value = x; 39 | value = x; 40 | 41 | BOOST_TEST(value.has_value()); 42 | BOOST_TEST(!value.has_enum()); 43 | BOOST_TEST(value.get_value() == x); 44 | 45 | bool is_call_on_value, is_call_on_enum; 46 | std::tie(is_call_on_value, is_call_on_enum) = call(value); 47 | BOOST_TEST(is_call_on_value); 48 | BOOST_TEST(!is_call_on_enum); 49 | 50 | call(value); 51 | } 52 | 53 | void enum_test() 54 | { 55 | shand::special_value value = E::e; 56 | 57 | BOOST_TEST(!value.has_value()); 58 | BOOST_TEST(value.has_enum()); 59 | BOOST_TEST(value.get_enum() == E::e); 60 | 61 | bool is_call_on_value, is_call_on_enum; 62 | std::tie(is_call_on_value, is_call_on_enum) = call(value); 63 | BOOST_TEST(!is_call_on_value); 64 | BOOST_TEST(is_call_on_enum); 65 | 66 | call(value); 67 | } 68 | 69 | int main() 70 | { 71 | value_test(3); 72 | value_test("hello"); 73 | 74 | enum_test(); 75 | 76 | return boost::report_errors(); 77 | } 78 | -------------------------------------------------------------------------------- /shand/optional_algorithm/max_element.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_OPTIONAL_ALGORITHM_MAX_ELEMENT_INCLUDE 2 | #define SHAND_OPTIONAL_ALGORITHM_MAX_ELEMENT_INCLUDE 3 | 4 | // Shand Optional Algorithm Library 5 | // 6 | // Copyright Akira Takahashi 2011 7 | // Use, modification and distribution is subject to the Boost Software License, 8 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 9 | // http://www.boost.org/LICENSE_1_0.txt) 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | namespace shand { namespace optional_algorithm { 16 | 17 | template 18 | inline boost::optional::type> 19 | max_element(ForwardRange& r) 20 | { 21 | typename boost::range_iterator::type it = boost::max_element(r); 22 | if (it != boost::end(r)) { 23 | return *it; 24 | } 25 | return boost::none; 26 | } 27 | 28 | template 29 | inline boost::optional::type> 30 | max_element(const ForwardRange& r) 31 | { 32 | typename boost::range_iterator::type it = boost::max_element(r); 33 | if (it != boost::end(r)) { 34 | return *it; 35 | } 36 | return boost::none; 37 | } 38 | 39 | template 40 | inline boost::optional::type> 41 | max_element(ForwardRange& r, BinaryPredicate pred) 42 | { 43 | typename boost::range_iterator::type it = boost::max_element(r, pred); 44 | if (it != boost::end(r)) { 45 | return *it; 46 | } 47 | return boost::none; 48 | } 49 | 50 | template 51 | inline boost::optional::type> 52 | max_element(const ForwardRange& r, BinaryPredicate pred) 53 | { 54 | typename boost::range_iterator::type it = boost::max_element(r, pred); 55 | if (it != boost::end(r)) { 56 | return *it; 57 | } 58 | return boost::none; 59 | } 60 | 61 | } // namespace optional_algorithm 62 | 63 | using optional_algorithm::max_element; 64 | 65 | } // namespace shand 66 | 67 | #endif // SHAND_OPTIONAL_ALGORITHM_MAX_ELEMENT_INCLUDE 68 | 69 | -------------------------------------------------------------------------------- /shand/optional_algorithm/min_element.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_OPTIONAL_ALGORITHM_MIN_ELEMENT_INCLUDE 2 | #define SHAND_OPTIONAL_ALGORITHM_MIN_ELEMENT_INCLUDE 3 | 4 | // Shand Optional Algorithm Library 5 | // 6 | // Copyright Akira Takahashi 2011 7 | // Use, modification and distribution is subject to the Boost Software License, 8 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 9 | // http://www.boost.org/LICENSE_1_0.txt) 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | namespace shand { namespace optional_algorithm { 16 | 17 | template 18 | inline boost::optional::type> 19 | min_element(ForwardRange& r) 20 | { 21 | typename boost::range_iterator::type it = boost::min_element(r); 22 | if (it != boost::end(r)) { 23 | return *it; 24 | } 25 | return boost::none; 26 | } 27 | 28 | template 29 | inline boost::optional::type> 30 | min_element(const ForwardRange& r) 31 | { 32 | typename boost::range_iterator::type it = boost::min_element(r); 33 | if (it != boost::end(r)) { 34 | return *it; 35 | } 36 | return boost::none; 37 | } 38 | 39 | template 40 | inline boost::optional::type> 41 | min_element(ForwardRange& r, BinaryPredicate pred) 42 | { 43 | typename boost::range_iterator::type it = boost::min_element(r, pred); 44 | if (it != boost::end(r)) { 45 | return *it; 46 | } 47 | return boost::none; 48 | } 49 | 50 | template 51 | inline boost::optional::type> 52 | min_element(const ForwardRange& r, BinaryPredicate pred) 53 | { 54 | typename boost::range_iterator::type it = boost::min_element(r, pred); 55 | if (it != boost::end(r)) { 56 | return *it; 57 | } 58 | return boost::none; 59 | } 60 | 61 | } // namespace optional_algorithm 62 | 63 | using optional_algorithm::min_element; 64 | 65 | } // namespace shand 66 | 67 | #endif // SHAND_OPTIONAL_ALGORITHM_MIN_ELEMENT_INCLUDE 68 | 69 | -------------------------------------------------------------------------------- /libs/encoding_string/doc/basic_usage.md: -------------------------------------------------------------------------------- 1 | # 基本的な使い方 2 | `encoding_string`クラスは、`std::basic_string`クラスのように文字型をテンプレート引数を設定するのではなく、文字コードを設定して使用する。 3 | 4 | ```cpp 5 | encoding_string utf16_str = u"あいうえお"; // UTF-16文字列 6 | encoding_string utf8_str = u8"あいうえお"; // UTF-8文字列 7 | encoding_string utf32_str = U"あいうえお"; // UTF-32文字列 8 | ``` 9 | 10 | 以下に述べる機能は、システム文字コード以外で使用可能である。 11 | 12 | ## 文字数を取得する 13 | `encoding_string::codeunit_size()`メンバ関数は、文字列に含まれるコードポイントの数を返す。文字数と考えていい。 14 | 15 | UTF-16のサロゲートペアもまた、1文字と数える。ただし、結合文字については複数文字として扱う(「が」という文字が「か」と「゛」で分かれていることがある)。結合文字はUnicodeの正規化を行えば1文字に変換可能である(未実装)。 16 | 17 | ```cpp 18 | encoding_string utf8_str = u8"あいうえお"; 19 | 20 | std::size_t n = utf8_str.codeunit_size(); // n == 5 21 | ``` 22 | 23 | ## i番目の文字を取得する 24 | `encoding_string::codeunit_at()`メンバ関数は、引数で指定したインデックスの文字を返す。 25 | 26 | `encoding_string`クラスにおいては、1文字もまた`encoding_string`文字列である。これはRuby 1.9以降の文字列の設計を踏襲している。 27 | 28 | ```cpp 29 | encoding_string utf8_str = u8"あいうえお"; 30 | 31 | // 2番目の文字を取得 32 | encoding_string at = utf8_str.codeunit_at(2); // at == u8"う" 33 | ``` 34 | 35 | ## 部分文字列を取得する 36 | `encoding_string::codeunit_substr()`メンバ関数は、`i`番目から`n`文字を抽出して返す。開始位置のみを指定した場合、開始位置以降の全ての文字列を返す。 37 | 38 | ```cpp 39 | encoding_string utf8_str = u8"あいうえお"; 40 | 41 | // 2番目から3文字を取得 42 | encoding_string sub1 = utf8_str.codeunit_substr(2, 3); 43 | // sub1 == u8"うえお" 44 | 45 | // 2番目以降の文字列を取得 46 | encoding_string sub2 = utf8_str.codeunit_substr(2); 47 | // sub2 == u8"うえお" 48 | ``` 49 | 50 | ## ストリーム出力 51 | `encoding_string`クラスは、`operator<<`によってストリーム出力ができる。この演算子を使用した場合、システム文字コード(`encoding::system`)に変換して出力される。 52 | 53 | ファイル出力の場合は任意の文字コードで出力したいであろうから、その場合は`operator<<`を使用すべきではない。`c_str()`メンバ関数によるC文字列の取得、もしくは`raw_str()`メンバ関数による`std::basic_string`オブジェクトの取得機能を使用すること。 54 | 55 | ```cpp 56 | encoding_string utf8_str = u8"あいうえお"; 57 | 58 | std::cout << utf8_str << std::endl; // あいうえお 59 | ``` 60 | 61 | 62 | ## イテレータ 63 | `encoding_string`クラスは、`begin()`/`end()`メンバ関数を持っている。これらによって、1文字ずつ順番に処理を行える。 64 | 65 | ```cpp 66 | encoding_string utf8_str = u8"あいうえお"; 67 | 68 | for (decltype(utf8_str)::value_type c : utf8_str) { 69 | std::cout << c << std::endl; 70 | } 71 | /* 72 | 以下の順に出力される: 73 | あ 74 | い 75 | う 76 | え 77 | お 78 | */ 79 | ``` 80 | 81 | -------------------------------------------------------------------------------- /shand/strict_types/integer.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_STRICT_TYPES_INTEGER_INCLUDE 2 | #define SHAND_STRICT_TYPES_INTEGER_INCLUDE 3 | 4 | // disallow bool conversion integer 5 | // 6 | // Copyright Akira Takahashi 2013 7 | // Use, modification and distribution is subject to the Boost Software License, 8 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 9 | // http://www.boost.org/LICENSE_1_0.txt) 10 | 11 | #include 12 | #include 13 | 14 | namespace shand { 15 | 16 | template 17 | class strict_integer : 18 | private boost::operators> { 19 | static_assert(std::is_integral{}, "T should integral type"); 20 | static_assert(!std::is_same{}, "T shouldn't bool type"); 21 | 22 | T value_; 23 | public: 24 | typedef T value_type; 25 | 26 | strict_integer(bool) = delete; 27 | strict_integer(T value = 0) : value_(value) {} 28 | 29 | T& get() { return value_; } 30 | const T& get() const { return value_; } 31 | 32 | strict_integer& operator=(bool) = delete; 33 | strict_integer& operator=(T x) 34 | { 35 | value_ = x; 36 | return *this; 37 | } 38 | 39 | // operators 40 | bool operator<(const strict_integer& x) const { return value_ < x.value_; } 41 | bool operator==(const strict_integer& x) const { return value_ == x.value_; } 42 | strict_integer& operator+=(const strict_integer& x) { value_ += x.value_; return *this; } 43 | strict_integer& operator-=(const strict_integer& x) { value_ -= x.value_; return *this; } 44 | strict_integer& operator*=(const strict_integer& x) { value_ *= x.value_; return *this; } 45 | strict_integer& operator/=(const strict_integer& x) { value_ /= x.value_; return *this; } 46 | strict_integer& operator%=(const strict_integer& x) { value_ %= x.value_; return *this; } 47 | 48 | strict_integer& operator&=(const strict_integer& x) { value_ &= x.value_; return *this; } 49 | strict_integer& operator|=(const strict_integer& x) { value_ |= x.value_; return *this; } 50 | strict_integer& operator^=(const strict_integer& x) { value_ ^= x.value_; return *this; } 51 | 52 | strict_integer& operator++() { ++value_; return *this; } 53 | strict_integer& operator--() { --value_; return *this; } 54 | }; 55 | 56 | } // namespace shand 57 | 58 | #endif // SHAND_STRICT_TYPES_INTEGER_INCLUDE 59 | 60 | -------------------------------------------------------------------------------- /shand/eigen_la.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_EIGEN_VECTOR_INCLUDE 2 | #define SHAND_EIGEN_VECTOR_INCLUDE 3 | 4 | // Copyright Akira Takahashi 2014 5 | // Use, modification and distribution is subject to the Boost Software License, 6 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | namespace shand { namespace la { 18 | 19 | template 20 | using vector = Eigen::Matrix; 21 | 22 | template 23 | using vector2 = vector; 24 | 25 | template 26 | using vector3 = vector; 27 | 28 | template 29 | using matrix2 = Eigen::Matrix; 30 | 31 | template 32 | using matrix3 = Eigen::Matrix; 33 | 34 | template 35 | using matrix4 = Eigen::Matrix; 36 | 37 | template 38 | using rotation2d = Eigen::Rotation2D; 39 | 40 | // caution : erase sign 41 | template 42 | radian_t vector_angle(const ::shand::la::vector& v, 43 | const ::shand::la::vector& u) 44 | { 45 | const T length = v.norm() * u.norm(); 46 | if (boost::geometry::math::equals(length, static_cast(0.0))) { 47 | return radian_t(0.0); 48 | } 49 | 50 | const T x = v.dot(u) / length; 51 | const T rounded = boost::algorithm::clamp(x, static_cast(-1.0), static_cast(1.0)); 52 | return radian_t(std::acos(rounded)); 53 | } 54 | 55 | template 56 | ::shand::la::matrix2 make_rotate2d_matrix(const ::shand::la::vector2& v) 57 | { 58 | ::shand::la::matrix2 m; 59 | m << 60 | v.x() /*cosθ*/, -v.y(), /*-sinθ*/ 61 | v.y() /*sinθ*/, v.x(); /*sinθ*/ 62 | return m; 63 | } 64 | 65 | template 66 | ::shand::la::rotation2d make_rotation2d(const ::shand::la::matrix2& m) 67 | { 68 | shand::la::rotation2d rotate(0.0f); 69 | rotate.fromRotationMatrix(m); 70 | return rotate; 71 | } 72 | 73 | template 74 | ::shand::la::rotation2d make_rotation2d(const ::shand::la::vector2& v) 75 | { 76 | return make_rotation2d(::shand::la::make_rotate2d_matrix(v)); 77 | } 78 | 79 | }} // namespace shand::la 80 | 81 | #endif // SHAND_EIGEN_VECTOR_INCLUDE 82 | 83 | -------------------------------------------------------------------------------- /shand/encoding_string/codeunit_iterator.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_ENCODING_STRING_CODEUNIT_ITERATOR_INCLUDE 2 | #define SHAND_ENCODING_STRING_CODEUNIT_ITERATOR_INCLUDE 3 | 4 | // Copyright Akira Takahashi 2013 5 | // Use, modification and distribution is subject to the Boost Software License, 6 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | namespace shand { 17 | 18 | template 22 | class codeunit_iterator : 23 | public boost::iterator_facade< 24 | codeunit_iterator, 25 | ElementStringType, 26 | boost::single_pass_traversal_tag, 27 | ElementStringType 28 | > 29 | { 30 | boost::optional data_; 31 | boost::optional pos_; 32 | boost::optional size_; 33 | public: 34 | codeunit_iterator() {} 35 | 36 | codeunit_iterator(const StringDataType& data) 37 | : data_(data) 38 | { 39 | if (data_.get().empty()) { 40 | pos_ = boost::none; 41 | } 42 | else { 43 | pos_ = BomSkipper()(data); 44 | } 45 | } 46 | 47 | private: 48 | friend class boost::iterator_core_access; 49 | 50 | void increment() 51 | { 52 | assert(pos_); 53 | 54 | const std::size_t size = SizeGetter()(data_.get(), pos_.get()); 55 | 56 | pos_.get() += size; 57 | size_ = size; 58 | 59 | if (pos_.get() >= data_.get().size()) 60 | pos_ = boost::none; 61 | } 62 | 63 | ElementStringType dereference() const 64 | { 65 | assert(pos_); 66 | 67 | std::size_t size = 0; 68 | if (size_) { 69 | size = size_.get(); 70 | } 71 | else { 72 | size = SizeGetter()(data_.get(), pos_.get()); 73 | } 74 | return StringDataType(data_.get(), pos_.get(), size).c_str(); 75 | } 76 | 77 | bool equal(const codeunit_iterator& other) const 78 | { 79 | return pos_ == other.pos_; 80 | } 81 | }; 82 | 83 | } // namespace shand 84 | 85 | #endif // SHAND_ENCODING_STRING_CODEUNIT_ITERATOR_INCLUDE 86 | 87 | -------------------------------------------------------------------------------- /shand/file_mapping_container.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_FILE_MAPPING_CONTAINER_INCLUDE 2 | #define SHAND_FILE_MAPPING_CONTAINER_INCLUDE 3 | 4 | // Shand File Mapping Container 5 | // 6 | // Copyright Akira Takahashi 2011 7 | // Use, modification and distribution is subject to the Boost Software License, 8 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 9 | // http://www.boost.org/LICENSE_1_0.txt) 10 | 11 | #if !defined(BOOST_DATE_TIME_NO_LIB) 12 | #define BOOST_DATE_TIME_NO_LIB 13 | #endif 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | namespace shand { 21 | 22 | namespace ipc = boost::interprocess; 23 | 24 | template 25 | class file_mapping_container { 26 | public: 27 | typedef ipc::allocator allocator_t; 28 | typedef ipc::vector container_t; 29 | 30 | file_mapping_container( 31 | ipc::create_only_t create_only, 32 | const std::string& filename, 33 | std::size_t filesize, 34 | const std::string& object_name) 35 | : managed_file_(create_only, filename.c_str(), filesize), 36 | allocator_(managed_file_.get_segment_manager()), 37 | container_(*(managed_file_.construct(object_name.c_str())(allocator_))) 38 | {} 39 | 40 | file_mapping_container( 41 | ipc::open_only_t open_only, 42 | const std::string& filename, 43 | const std::string& object_name) 44 | : managed_file_(open_only, filename.c_str()), 45 | allocator_(managed_file_.get_segment_manager()), 46 | container_(*(managed_file_.find(object_name.c_str()).first)) 47 | { 48 | } 49 | 50 | file_mapping_container( 51 | ipc::open_or_create_t open_or_create, 52 | const std::string& filename, 53 | std::size_t filesize, 54 | const std::string& object_name) 55 | : managed_file_(open_or_create, filename.c_str(), filesize), 56 | allocator_(managed_file_.get_segment_manager()), 57 | container_(*(managed_file_.find_or_construct(object_name.c_str())(allocator_))) 58 | {} 59 | 60 | container_t& get() { return container_; } 61 | const container_t& get() const { return container_; } 62 | 63 | private: 64 | ipc::managed_mapped_file managed_file_; 65 | allocator_t allocator_; 66 | container_t& container_; 67 | }; 68 | 69 | } // namespace shand 70 | 71 | #endif // SHAND_FILE_MAPPING_CONTAINER_INCLUDE 72 | 73 | -------------------------------------------------------------------------------- /libs/encoding_string/doc/reference/encoding_string.md: -------------------------------------------------------------------------------- 1 | # `` 2 | 3 | ## 概要 4 | ```cpp 5 | namespace shand { 6 | 7 | // エンコーディングの種類 8 | namespace encoding { 9 | struct utf16 {}; 10 | struct utf8 {}; 11 | struct utf32 {}; 12 | struct system {}; 13 | } // namespace encoding 14 | 15 | // エンコード文字列 16 | template 17 | class encoding_string; 18 | 19 | // 文字コードの変換 20 | template 21 | encoding_string encode(const encoding_string& from); 22 | 23 | // ストリーム出力 24 | template 25 | std::basic_ostream& 26 | operator<<(std::basic_ostream& os, const encoding_string& s); 27 | 28 | // Unicode正規化 29 | template 30 | encoding_string compose(const encoding_string& s); 31 | 32 | template 33 | encoding_string decompose(const encoding_string& s); 34 | 35 | template 36 | encoding_string compatible_compose(const encoding_string& s); 37 | 38 | template 39 | encoding_string compatible_decompose(const encoding_string& s); 40 | 41 | } // namespace shand 42 | ``` 43 | 44 | ## エンコーディングの種類 45 | 46 | エンコーディングの種類は、`shand::encoding`名前空間内に、それぞれ空クラスのタグとして定義している。 47 | 48 | | 名前 | 説明 | 49 | |------------------------|--------------------------------------------| 50 | | `utf16` | UTF-16。システムのエンディアンを使用する。 | 51 | | `utf8` | UTF-8 | 52 | | `utf32` | UTF-32。システムのエンディアンを使用する。 | 53 | | `system` | システムの文字コード。ストリームの出力に使用する文字コード。 | 54 | 55 | 56 | ## エンコード文字列クラスと、エンコード関数 57 | 58 | | 名前 | 説明 | 59 | |-------------------|---------------------------------------------------------------| 60 | | [`encoding_string`](./encoding_string/encoding_string.md) | 文字コードのエンコーディング情報を持つ文字列クラス | 61 | | `encode()` | `encoding_string`オブジェクトを、他の文字コードに変換する関数 | 62 | | `operator<<` | ストリーム出力 | 63 | 64 | ## Unicode正規化 65 | 66 | | 名前 | 説明 | 67 | |--------------------------|----------------| 68 | | `compose()` | 結合文字を合成する関数(Windows環境のみ実装している) | 69 | | `decompose()` | 文字を結合文字に分解する関数(Windows環境のみ実装している) | 70 | | `compatible_compose()` | 結合文字を、互換性のある文字に合成する関数(Windows環境のみ実装している) | 71 | | `compatible_decompose()` | 文字を、互換性のある結合文字に分解する関数(Windows環境のみ実装している) | 72 | 73 | 74 | -------------------------------------------------------------------------------- /shand/strong_typedef/tagged_float.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_TAGGED_FLOAT_INCLUDE 2 | #define SHAND_TAGGED_FLOAT_INCLUDE 3 | 4 | // strong typedef for floating point types. 5 | // 6 | // Copyright Akira Takahashi 2012-2015. 7 | // Use, modification and distribution is subject to the Boost Software License, 8 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 9 | // http://www.boost.org/LICENSE_1_0.txt) 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #if !defined(BOOST_NO_CXX11_NOEXCEPT) 18 | #define SHAND_NOEXCEPT_COND(cond) noexcept(cond) 19 | #define SHAND_NOEXCEPT_IF(expr) noexcept(noexcept(expr)) 20 | #else 21 | #define SHAND_NOEXCEPT_COND(cond) 22 | #define SHAND_NOEXCEPT_IF(expr) 23 | #endif 24 | 25 | namespace shand { 26 | 27 | template // Tag is phantom type 28 | class tagged_float : 29 | private boost::operators > { 30 | 31 | BOOST_STATIC_ASSERT(boost::is_floating_point::value); 32 | 33 | FloatingPoint value_; 34 | public: 35 | typedef FloatingPoint value_type; 36 | 37 | explicit tagged_float(FloatingPoint value = 0) 38 | SHAND_NOEXCEPT_COND(boost::has_nothrow_copy_constructor::value) 39 | : value_(value) {} 40 | 41 | FloatingPoint& get() BOOST_NOEXCEPT { return value_; } 42 | const FloatingPoint& get() const BOOST_NOEXCEPT { return value_; } 43 | 44 | // operators 45 | bool operator<(const tagged_float& x) const SHAND_NOEXCEPT_IF(value_ < x.value_) 46 | { return value_ < x.value_; } 47 | tagged_float& operator+=(const tagged_float& x) SHAND_NOEXCEPT_IF(value_ += x.value_) 48 | { value_ += x.value_; return *this; } 49 | tagged_float& operator-=(const tagged_float& x) SHAND_NOEXCEPT_IF(value_ -= x.value_) 50 | { value_ -= x.value_; return *this; } 51 | tagged_float& operator*=(const tagged_float& x) SHAND_NOEXCEPT_IF(value_ *= x.value_) 52 | { value_ *= x.value_; return *this; } 53 | tagged_float& operator/=(const tagged_float& x) SHAND_NOEXCEPT_IF(value_ /= x.value_) 54 | { value_ /= x.value_; return *this; } 55 | 56 | bool equals(const tagged_float& x) const SHAND_NOEXCEPT_IF(boost::geometry::math::equals(value_, x.value_)) 57 | { 58 | return boost::geometry::math::equals(value_, x.value_); 59 | } 60 | }; 61 | 62 | } // namespace shand 63 | 64 | #endif 65 | 66 | -------------------------------------------------------------------------------- /shand/special_value.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_SPECIAL_VALUE_INCLUDE 2 | #define SHAND_SPECIAL_VALUE_INCLUDE 3 | 4 | // Variant of arithmetic type and enum (special value) 5 | // For example, The class can use for pop view : 6 | // special_value v; 7 | // v = 1; 8 | // v = PopType::Root; 9 | // 10 | // Copyright Akira Takahashi 2014 11 | // Use, modification and distribution is subject to the Boost Software License, 12 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 13 | // http://www.boost.org/LICENSE_1_0.txt) 14 | 15 | #include 16 | 17 | namespace shand { 18 | 19 | template 20 | class special_value { 21 | boost::variant value_; 22 | public: 23 | using value_type = ValueType; 24 | using enum_type = Enum; 25 | 26 | special_value() {} // initialize ValueType 27 | 28 | special_value(ValueType value) 29 | : value_(value) {} 30 | 31 | special_value(Enum e) 32 | : value_(e) {} 33 | 34 | special_value& operator=(ValueType value) 35 | { 36 | value_ = value; 37 | return *this; 38 | } 39 | 40 | special_value& operator=(Enum e) 41 | { 42 | value_ = e; 43 | return *this; 44 | } 45 | 46 | bool has_value() const 47 | { return value_.which() == 0; } 48 | 49 | bool has_enum() const 50 | { return value_.which() == 1; } 51 | 52 | ValueType& get_value() 53 | { return boost::get(value_); } 54 | 55 | const ValueType& get_value() const 56 | { return boost::get(value_); } 57 | 58 | Enum& get_enum() 59 | { return boost::get(value_); } 60 | 61 | const Enum& get_enum() const 62 | { return boost::get(value_); } 63 | 64 | template // void(ValueType& value) or void(ValueType& value) 65 | special_value& on_value(F f) 66 | { 67 | if (has_value()) { 68 | f(get_value()); 69 | } 70 | return *this; 71 | } 72 | 73 | template 74 | const special_value& on_value(F f) const 75 | { 76 | return const_cast(*this).on_value(f); 77 | } 78 | 79 | template // void(Enum value) or void(Enum& value) 80 | special_value& on_enum(F f) 81 | { 82 | if (has_enum()) { 83 | f(get_enum()); 84 | } 85 | return *this; 86 | } 87 | 88 | template 89 | const special_value& on_enum(F f) const 90 | { 91 | return const_cast(*this).on_enum(f); 92 | } 93 | }; 94 | 95 | } // namespace shand 96 | 97 | #endif // SHAND_SPECIAL_VALUE_INCLUDE 98 | 99 | -------------------------------------------------------------------------------- /libs/match/test/match.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Akira Takahashi 2015 2 | // Use, modification and distribution is subject to the Boost Software License, 3 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | void test_one_arg_value_call() 11 | { 12 | boost::optional opt = 3; 13 | 14 | bool called = false; 15 | shand::match(opt, [&](int& x) { 16 | BOOST_TEST(x == opt.get()); 17 | called = true; 18 | }); 19 | BOOST_TEST(called); 20 | } 21 | 22 | void test_one_arg_none_not_call() 23 | { 24 | boost::optional opt = 3; 25 | 26 | bool called = false; 27 | shand::match(opt, [&called] { 28 | called = true; 29 | }); 30 | BOOST_TEST(!called); 31 | } 32 | 33 | void test_one_arg_value_not_call() 34 | { 35 | boost::optional opt; 36 | 37 | bool called = false; 38 | shand::match(opt, [&called](int&) { 39 | called = true; 40 | }); 41 | BOOST_TEST(!called); 42 | } 43 | 44 | void test_one_arg_none_call() 45 | { 46 | boost::optional opt; 47 | 48 | bool called = false; 49 | shand::match(opt, [&called] { 50 | called = true; 51 | }); 52 | BOOST_TEST(called); 53 | } 54 | 55 | void test_two_args_has_value() 56 | { 57 | boost::optional opt = 3; 58 | 59 | bool has_value_called = false; 60 | bool none_called = false; 61 | 62 | shand::match(opt, 63 | [&](int& x) { 64 | BOOST_TEST(x == opt.get()); 65 | has_value_called = true; 66 | }, 67 | [&] { 68 | none_called = true; 69 | } 70 | ); 71 | 72 | BOOST_TEST(has_value_called); 73 | BOOST_TEST(!none_called); 74 | } 75 | 76 | void test_two_args_none() 77 | { 78 | boost::optional opt; 79 | 80 | bool has_value_called = false; 81 | bool none_called = false; 82 | 83 | shand::match(opt, 84 | [&](int&) { 85 | has_value_called = true; 86 | }, 87 | [&] { 88 | none_called = true; 89 | } 90 | ); 91 | 92 | BOOST_TEST(!has_value_called); 93 | BOOST_TEST(none_called); 94 | } 95 | 96 | int main() 97 | { 98 | test_one_arg_value_call(); 99 | test_one_arg_none_not_call(); 100 | 101 | test_one_arg_value_not_call(); 102 | test_one_arg_none_call(); 103 | 104 | test_two_args_has_value(); 105 | test_two_args_none(); 106 | 107 | return boost::report_errors(); 108 | } 109 | -------------------------------------------------------------------------------- /libs/encoding_string/doc/future_plan.md: -------------------------------------------------------------------------------- 1 | # 将来の予定 2 | 3 | ## 文字のイテレートと、文字数取得のインタフェース 4 | 5 | 現在は、コードユニット(コードポイント)でのインタフェースのみ提供しているが、文字でのインタフェースの実装を考えている。 6 | 7 | ### 実装方針案(考え中) 8 | 9 | デフォルトポリシーとして、以下の方針で文字数を数える。このポリシーをカスタマイズ可能にするかは、検討中。 10 | 11 | 12 | 以下のパターンに合致するものを、1文字と数える: 13 | 14 | - 文字列先頭の結合文字 x 1 15 | - 基底文字 16 | - 基底文字 + (結合文字 x n) 17 | - 基底文字 + (結合文字 x n) + (異体字セレクタ x 1) 18 | 19 | 20 | 以下のパターンに合致するものを、0文字と数える: 21 | 22 | - ゼロ幅文字 23 | 24 | 25 | ### なぜNFC後のコードユニット数 + 異体字セレクタではいけないのか 26 | 27 | NFCは、NFDで分解した後に、合成除外表に載っていないもののみ合成する。そのため、NFCでは合成されない結合文字が存在する。 28 | 29 | 合成されない結合文字も、ポリシーのカスタマイズによって1文字と数える必要があるかもしれない。 30 | 31 | 32 | ### 実装検討中の部品 33 | 34 | - 異体字セレクタか判定する`is_variation_selector()` 35 | 36 | ```cpp 37 | bool is_variation_selector(char32_t codeunit) 38 | { 39 | return (codeunit >= 0x180b && codeunit <= 0x180d) || 40 | (codeunit >= 0xfe00 && codeunit <= 0xfe0f) || 41 | (codeunit >= 0xe0100 && codeunit <= 0xe01ef); 42 | } 43 | ``` 44 | 45 | - 結合文字か判定する`is_combining_character()` 46 | 47 | ```cpp 48 | #include 49 | #include 50 | #include 51 | 52 | // 結合文字か判定する 53 | bool is_combining_character(char32_t codeunit) 54 | { 55 | UErrorCode error_code = U_ZERO_ERROR; 56 | const icu::Normalizer2* normalizer = icu::Normalizer2::getNFCInstance(error_code); 57 | if (U_FAILURE(error_code)) { 58 | throw std::runtime_error( 59 | std::string("failed icu::Normalizer2::getNFCInstance() : ") + u_errorName(error_code)); 60 | } 61 | 62 | return normalizer->getCombiningClass(UChar32(codeunit)) > 0; 63 | } 64 | 65 | #include 66 | int main() 67 | { 68 | std::cout << std::boolalpha; 69 | std::cout << is_combining_character(U'a') << std::endl; // false 70 | std::cout << is_combining_character(U'\U0000032F') << std::endl; // true 71 | std::cout << is_combining_character(U' ̎') << std::endl; // true 72 | } 73 | ``` 74 | 75 | - ゼロ幅文字を判定する`is_zero_width_character(char32_t codeunit)` 76 | 77 | ```cpp 78 | bool is_zero_width_character(char32_t codeunit) 79 | { 80 | return codeunit == 0x200b || // ZERO WIDTH SPACE 81 | codeunit == 0x2029 || // PARAGRAPH SEPARATOR 82 | codeunit == 0x202a; // LEFT-TO-RIGHT EMBEDDING 83 | } 84 | ``` 85 | 86 | 87 | ## ICUベースの正規化 88 | 89 | ICUベースの、以下の実装を用意する: 90 | 91 | - `compose()` 92 | - `decompose()` 93 | - `compatibility_compose()` 94 | - `compatibility_decompose()` 95 | 96 | 97 | ## エンコード情報付きファイルクラス 98 | 99 | `encoding_string`クラスは、エンディアンの情報を扱わず、文字・文字列の情報のみを扱う。そのため、エンディアンの情報を吸収するクラスとして、`encoding_file`クラスを作成する予定。 100 | 101 | 102 | # 当面やらないもの 103 | 104 | - 正規表現 : Boost.RegexにICUのラッパーがあるので、それを使って十分なはず。十分でない場合は検討する。 105 | 106 | 107 | -------------------------------------------------------------------------------- /libs/strong_typedef/test_tagged_float.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Akira Takahashi 2012 2 | // Use, modification and distribution is subject to the Boost Software License, 3 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | struct tag {}; 12 | typedef shand::tagged_float floating_point; 13 | 14 | int main () 15 | { 16 | // initialize 17 | floating_point x(1.0); 18 | const floating_point& cx = x; 19 | 20 | // reference 21 | double& ref = x.get(); 22 | const double& cref = cx.get(); 23 | BOOST_TEST(x.equals(floating_point(ref))); 24 | BOOST_TEST(x.equals(floating_point(cref))); 25 | 26 | // relational operators 27 | BOOST_TEST(x.equals(floating_point(1.0))); 28 | BOOST_TEST(x < floating_point(2.0)); 29 | BOOST_TEST(x <= floating_point(2.0)); 30 | BOOST_TEST(x > floating_point(0.1)); 31 | BOOST_TEST(x >= floating_point(0.1)); 32 | 33 | // add operators 34 | { 35 | floating_point y(1.0); 36 | y += floating_point(2.0); 37 | BOOST_TEST(y.equals(floating_point(3.0))); 38 | 39 | floating_point z = floating_point(1.0) + floating_point(2.0); 40 | BOOST_TEST(z.equals(floating_point(3.0))); 41 | } 42 | 43 | // subtract operators 44 | { 45 | floating_point y(3.0); 46 | y -= floating_point(1.0); 47 | BOOST_TEST(y.equals(floating_point(2.0))); 48 | 49 | floating_point z = floating_point(3.0) - floating_point(1.0); 50 | BOOST_TEST(z.equals(floating_point(2.0))); 51 | } 52 | 53 | // multiply operators 54 | { 55 | floating_point y(3.0); 56 | y *= floating_point(2.0); 57 | BOOST_TEST(y.equals(floating_point(6.0))); 58 | 59 | floating_point z = floating_point(3.0) * floating_point(2.0); 60 | BOOST_TEST(z.equals(floating_point(6.0))); 61 | } 62 | 63 | // divide operators 64 | { 65 | floating_point y(6.0); 66 | y /= floating_point(2.0); 67 | BOOST_TEST(y.equals(floating_point(3.0))); 68 | 69 | floating_point z = floating_point(6.0) / floating_point(2.0); 70 | BOOST_TEST(z.equals(floating_point(3.0))); 71 | } 72 | 73 | // output stream 74 | { 75 | floating_point y(3.0); 76 | std::ostringstream ss; 77 | ss << y; 78 | BOOST_TEST(ss.str() == "3"); 79 | } 80 | 81 | // input stream 82 | { 83 | floating_point y; 84 | std::stringstream ss; 85 | ss << "3.0"; 86 | ss >> y; 87 | BOOST_TEST(y.equals(floating_point(3.0))); 88 | } 89 | 90 | return boost::report_errors(); 91 | } 92 | 93 | -------------------------------------------------------------------------------- /shand/static_map.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_STATIC_MAP_INCLUDE 2 | #define SHAND_STATIC_MAP_INCLUDE 3 | 4 | // Compile time fixed capacity map. 5 | // 6 | // Copyright Akira Takahashi, myoukaku 2013-2014. 7 | // Use, modification and distribution is subject to the Boost Software License, 8 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 9 | // http://www.boost.org/LICENSE_1_0.txt) 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | namespace shand { 18 | 19 | template > 20 | class static_map { 21 | using value_type = std::pair; 22 | boost::container::static_vector cont_; 23 | public: 24 | static_map(std::initializer_list init) 25 | : cont_(init.begin(), init.end()) 26 | { 27 | boost::sort(cont_, [](const value_type& a, const value_type& b) { 28 | return Compare()(a.first, b.first); 29 | }); 30 | } 31 | 32 | template 33 | const T& at(const KeyType& key) const 34 | { 35 | auto it = boost::lower_bound(cont_, key, 36 | [](const value_type& a, const KeyType& b) { 37 | return Compare()(a.first, b); 38 | }); 39 | 40 | if (it != cont_.end()) { 41 | if (!Compare()(it->first, key) && !Compare()(key, it->first)) { 42 | return it->second; 43 | } 44 | } 45 | throw std::out_of_range("out of range error"); 46 | } 47 | }; 48 | 49 | // usage : 50 | // 51 | // enum class Color { 52 | // Blue, 53 | // Yellow, 54 | // Red 55 | // }; 56 | // 57 | // shand::pair_maker p; 58 | // const auto map = shand::make_static_map( 59 | // p(Color::Blue, "AAA"), 60 | // p(Color::Yellow, "BBB"), 61 | // p(Color::Red, "CCC") 62 | // ); 63 | // 64 | // std::string s = map.at(Color::Blue); 65 | template 66 | struct pair_maker { 67 | std::pair operator()(Key&& key, T&& value) const 68 | { 69 | return {std::move(key), std::move(value)}; 70 | } 71 | }; 72 | 73 | template 74 | auto make_static_map(std::pair&&... args) 75 | -> static_map< 76 | typename std::common_type::type, 77 | typename std::common_type::type, 78 | sizeof...(Keys)> 79 | { 80 | return static_map< 81 | typename std::common_type::type, 82 | typename std::common_type::type, 83 | sizeof...(Keys)>({args...}); 84 | } 85 | 86 | } // namespace shand 87 | 88 | #endif // SHAND_STATIC_MAP_INCLUDE 89 | 90 | -------------------------------------------------------------------------------- /shand/errorable.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_ERRORABLE_INCLUDE 2 | #define SHAND_ERRORABLE_INCLUDE 3 | 4 | // Shand C++ Library 5 | // 6 | // Copyright Akira Takahashi 2013 7 | // Use, modification and distribution is subject to the Boost Software License, 8 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 9 | // http://www.boost.org/LICENSE_1_0.txt) 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | namespace shand { 17 | 18 | template 19 | class error_t { 20 | T value_; 21 | public: 22 | error_t() : value_() {} 23 | 24 | error_t(const T& value) 25 | : value_(value) {} 26 | 27 | template 28 | error_t(const error_t& other) 29 | : value_(other.what()) {} 30 | 31 | const T& what() const 32 | { 33 | return value_; 34 | } 35 | }; 36 | 37 | template 38 | error_t::type> error(T&& value) 39 | { 40 | return error_t::type>(value); 41 | } 42 | 43 | template 44 | class errorable { 45 | boost::variant, T> value_; 46 | public: 47 | errorable() {} 48 | 49 | template 50 | errorable(const error_t& err) 51 | : value_(error_t(err)) {} 52 | 53 | errorable(const T& value) 54 | : value_(value) {} 55 | 56 | errorable& operator=(const error_t& err) 57 | { 58 | value_ = err; 59 | return *this; 60 | } 61 | 62 | errorable& operator=(const T& value) 63 | { 64 | value_ = value; 65 | return *this; 66 | } 67 | 68 | boost::optional get_value() const 69 | { 70 | if (value_.which() == 1) { 71 | return boost::get(value_); 72 | } 73 | return boost::none; 74 | } 75 | 76 | boost::optional get_error() const 77 | { 78 | if (value_.which() == 0) { 79 | return boost::get>(value_).what(); 80 | } 81 | return boost::none; 82 | } 83 | 84 | bool is_error() const { return value_.which() == 0; } 85 | 86 | template 87 | const errorable& value_if(F f) const 88 | { 89 | if (value_.which() == 1) { 90 | f(boost::get(value_)); 91 | } 92 | return *this; 93 | } 94 | 95 | template 96 | const errorable& error_if(F f) const 97 | { 98 | if (value_.which() == 0) { 99 | f(boost::get>(value_).what()); 100 | } 101 | return *this; 102 | } 103 | }; 104 | 105 | 106 | } // namespace shand 107 | 108 | #endif // SHAND_ERRORABLE_INCLUDE 109 | 110 | -------------------------------------------------------------------------------- /shand/immutable_vector.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_IMMUTABLE_VECTOR_INCLUDE 2 | #define SHAND_IMMUTABLE_VECTOR_INCLUDE 3 | 4 | // Copyright Akira Takahashi 2014 5 | // Use, modification and distribution is subject to the Boost Software License, 6 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | namespace shand { 15 | 16 | template > 17 | using vector_builder = std::vector; 18 | 19 | template > 20 | class immutable_vector { 21 | std::vector vec_; 22 | public: 23 | using vector_type = std::vector; 24 | using iterator = typename vector_type::const_iterator; 25 | using const_iterator = typename vector_type::const_iterator; 26 | using value_type = typename vector_type::value_type; 27 | using size_type = typename vector_type::size_type; 28 | using difference_type = typename vector_type::difference_type; 29 | 30 | immutable_vector() {} 31 | immutable_vector(vector_builder&& builder) 32 | : vec_(std::move(builder)) {} 33 | 34 | immutable_vector(const immutable_vector&) = delete; 35 | immutable_vector& operator=(const immutable_vector&) = delete; 36 | 37 | void build(vector_builder&& builder) 38 | { 39 | vec_ = std::move(builder); 40 | } 41 | 42 | const_iterator begin() const BOOST_NOEXCEPT { return vec_.cbegin(); } 43 | const_iterator cbegin() const BOOST_NOEXCEPT { return vec_.cbegin(); } 44 | 45 | const_iterator end() const BOOST_NOEXCEPT { return vec_.cend(); } 46 | const_iterator cend() const BOOST_NOEXCEPT { return vec_.cend(); } 47 | 48 | size_type size() const BOOST_NOEXCEPT { return vec_.size(); } 49 | bool empty() const BOOST_NOEXCEPT { return vec_.empty(); } 50 | 51 | const T& operator[](size_type n) const 52 | { return vec_[n]; } 53 | 54 | const T& at(size_type n) const 55 | { return vec_.at(n); } 56 | 57 | boost::optional opt_at(size_t n) const BOOST_NOEXCEPT 58 | { 59 | if (n < size()) 60 | return vec_[n]; 61 | return boost::none; 62 | } 63 | 64 | boost::optional opt_front() const BOOST_NOEXCEPT 65 | { 66 | if (!empty()) 67 | return vec_[0u]; 68 | return boost::none; 69 | } 70 | 71 | boost::optional opt_back() const BOOST_NOEXCEPT 72 | { 73 | if (!empty()) 74 | return vec_[size() - 1u]; 75 | return boost::none; 76 | } 77 | 78 | // reference raw data 79 | const T* data() const BOOST_NOEXCEPT { return vec_.data(); } 80 | const vector_type& get() const BOOST_NOEXCEPT { return vec_; } 81 | }; 82 | 83 | } // namespace shand 84 | 85 | #endif // SHAND_IMMUTABLE_VECTOR_INCLUDE 86 | 87 | -------------------------------------------------------------------------------- /shand/encoding_string.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_ENCODING_STRING_INCLUDE 2 | #define SHAND_ENCODING_STRING_INCLUDE 3 | 4 | // encoding string 5 | // http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3572.html 6 | // 7 | // Copyright Akira Takahashi 2013 8 | // Use, modification and distribution is subject to the Boost Software License, 9 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 10 | // http://www.boost.org/LICENSE_1_0.txt) 11 | 12 | // TODO: 13 | // - add `encoding_file` class. The class manage endian and BOM. 14 | // - documentation. use GitHub Wiki. 15 | 16 | #include 17 | 18 | namespace shand { 19 | 20 | namespace encoding { 21 | 22 | struct utf16 {}; 23 | struct utf8 {}; 24 | struct utf32 {}; 25 | struct system {}; 26 | 27 | } // namespace encoding 28 | 29 | template 30 | class encoding_string; 31 | 32 | } // namespace shand 33 | 34 | #include "./encoding_string/utf16_string.hpp" 35 | #include "./encoding_string/utf8_string.hpp" 36 | #include "./encoding_string/utf32_string.hpp" 37 | #include "./encoding_string/system_string.hpp" 38 | 39 | #include "./encoding_string/encoder.hpp" 40 | 41 | namespace shand { 42 | 43 | template 44 | encoding_string encode(const encoding_string& from) 45 | { 46 | return encoder::encode(from); 47 | } 48 | 49 | template 50 | std::basic_ostream& operator<<(std::basic_ostream& os, const encoding_string& s) 51 | { 52 | return os << encode(s).c_str(); 53 | } 54 | 55 | } // namespace shand 56 | 57 | #include "./encoding_string/normalizer.hpp" 58 | 59 | namespace shand { 60 | 61 | // NFC (Normalization Form Canonical Composition) 62 | // Please don't use this function yet. imcomplete implementation. 63 | template 64 | encoding_string compose(const encoding_string& s) 65 | { 66 | return normalizer::compose(s); 67 | } 68 | 69 | // NFD (Normalization Form Canonical Decomposition) 70 | // Please don't use this function yet. imcomplete implementation. 71 | template 72 | encoding_string decompose(const encoding_string& s) 73 | { 74 | return normalizer::decompose(s); 75 | } 76 | 77 | // NFKC (Normalization Form Compatibility Composition) 78 | // Please don't use this function yet. imcomplete implementation. 79 | template 80 | encoding_string compatible_compose(const encoding_string& s) 81 | { 82 | return normalizer::compatible_compose(s); 83 | } 84 | 85 | // NFKD (Normalization Form Compatibility Decomposition) 86 | // Please don't use this function yet. imcomplete implementation. 87 | template 88 | encoding_string compatible_decompose(const encoding_string& s) 89 | { 90 | return normalizer::compatible_decompose(s); 91 | } 92 | 93 | } // namespace shand 94 | 95 | #endif // SHAND_ENCODING_STRING_INCLUDE 96 | 97 | -------------------------------------------------------------------------------- /shand/old/istream_line.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_ISTREAM_LINE_INCLUDE 2 | #define SHAND_ISTREAM_LINE_INCLUDE 3 | 4 | // Copyright Akira Takahashi 2007 5 | // Use, modification and distribution is subject to the Boost Software License, 6 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | #include 11 | 12 | namespace shand { 13 | 14 | template , 16 | class Allocator = std::allocator > 17 | class istream_line_iterator { 18 | public: 19 | typedef CharT char_type; 20 | typedef Traits traits_type; 21 | typedef Allocator allocator_type; 22 | typedef std::basic_istream istream_type; 23 | typedef std::basic_string string_type; 24 | 25 | typedef std::forward_iterator_tag iterator_category; 26 | typedef string_type value_type; 27 | typedef size_t difference_type; 28 | typedef string_type* pointer; 29 | typedef string_type& reference; 30 | 31 | istream_line_iterator() 32 | : in_ptr_(0), delim_(), line_(){} 33 | 34 | explicit istream_line_iterator(istream_type& is) 35 | : in_ptr_(&is), delim_(is.widen('\n')), line_() 36 | { 37 | increment(); 38 | } 39 | 40 | istream_line_iterator(istream_type& is, CharT delim) 41 | : in_ptr_(&is), delim_(delim), line_() 42 | { 43 | increment(); 44 | } 45 | 46 | istream_line_iterator& operator++ () { increment(); return *this; } 47 | istream_line_iterator operator++ (int) { istream_line_iterator own(*this); increment(); return own; } 48 | string_type& operator* () { return dereference(); } 49 | bool operator== (const istream_line_iterator& rhs) const { return equal(rhs); } 50 | bool operator!= (const istream_line_iterator& rhs) const { return !equal(rhs); } 51 | 52 | private: 53 | istream_type* in_ptr_; 54 | CharT delim_; 55 | string_type line_; 56 | 57 | string_type& dereference() 58 | { 59 | return line_; 60 | } 61 | 62 | void increment() 63 | { 64 | if (!std::getline(*in_ptr_, line_, delim_)) 65 | in_ptr_ = 0; 66 | } 67 | 68 | bool equal(const istream_line_iterator& rhs) const 69 | { 70 | return in_ptr_ == rhs.in_ptr_; 71 | } 72 | }; 73 | 74 | template 75 | std::pair, istream_line_iterator > 76 | make_istream_line_range(std::basic_istream& is) 77 | { 78 | typedef istream_line_iterator istream_line_iterator_t; 79 | return std::make_pair(istream_line_iterator_t(is), istream_line_iterator_t()); 80 | } 81 | 82 | } // namespace shand 83 | 84 | #endif // SHAND_ISTREAM_LINE_INCLUDE 85 | 86 | -------------------------------------------------------------------------------- /shand/match.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_MATCH_INCLUDE 2 | #define SHAND_MATCH_INCLUDE 3 | 4 | // Copyright Akira Takahashi 2015 5 | // Use, modification and distribution is subject to the Boost Software License, 6 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | // 9 | // Inspired by follow : 10 | // https://groups.google.com/a/isocpp.org/forum/#!topic/std-proposals/31glnrmsNaY 11 | // https://github.com/viboes/tags/blob/master/doc/proposals/match/DXXXX_Match.md 12 | 13 | #include 14 | #include 15 | 16 | namespace shand { 17 | 18 | namespace match_detail { 19 | 20 | template 21 | void call_value(Optional& opt, F f, std::true_type) 22 | { 23 | f(opt.get()); 24 | } 25 | 26 | template 27 | void call_value(Optional&, F, std::false_type) {} 28 | 29 | template 30 | void call_none(F f, std::true_type) 31 | { 32 | f(); 33 | } 34 | 35 | template 36 | void call_none(F, std::false_type) {} 37 | 38 | } // namespace match_detail 39 | 40 | 41 | // for `boost::optional` 42 | // 43 | // `F` is `R(T&)` or `R(const T&)` or `R()`. 44 | // 45 | // `F` is `R(T&)` or `R(const T&)` : 46 | // If `x` has value, call `f(x.get())`, Otherwise not call. 47 | // `F` is `R()` : 48 | // If `x` is `none`, call `f()`, Otherwise not call. 49 | template 50 | void match(boost::optional& x, F f) 51 | { 52 | if (x) { 53 | match_detail::call_value(x, f, shand::is_callable()); 54 | } 55 | else { 56 | match_detail::call_none(f, shand::is_callable()); 57 | } 58 | } 59 | 60 | template 61 | void match(const boost::optional& x, F f) 62 | { 63 | if (x) { 64 | match_detail::call_value(x, f, shand::is_callable()); 65 | } 66 | else { 67 | match_detail::call_none(f, shand::is_callable()); 68 | } 69 | } 70 | 71 | 72 | template 73 | void match(boost::optional& x, F1 f1, F2 f2) 74 | { 75 | if (x) { 76 | match_detail::call_value(x, f1, shand::is_callable()); 77 | match_detail::call_value(x, f2, shand::is_callable()); 78 | } 79 | else { 80 | match_detail::call_none(f1, shand::is_callable()); 81 | match_detail::call_none(f2, shand::is_callable()); 82 | } 83 | } 84 | 85 | template 86 | void match(const boost::optional& x, F1 f1, F2 f2) 87 | { 88 | if (x) { 89 | match_detail::call_value(x, f1, shand::is_callable()); 90 | match_detail::call_value(x, f2, shand::is_callable()); 91 | } 92 | else { 93 | match_detail::call_none(f1, shand::is_callable()); 94 | match_detail::call_none(f2, shand::is_callable()); 95 | } 96 | } 97 | 98 | } // namespace shand 99 | 100 | #endif // SHAND_MATCH_INCLUDE 101 | 102 | -------------------------------------------------------------------------------- /shand/old/shared_array.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_SHARED_ARRAY_INCLUDE 2 | #define SHAND_SHARED_ARRAY_INCLUDE 3 | 4 | // (C) Copyright Greg Colvin and Beman Dawes 1998, 1999. 5 | // Copyright (c) 2001, 2002 Peter Dimov 6 | // Copyright Akira Takahashi 2007 7 | // Use, modification and distribution is subject to the Boost Software License, 8 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 9 | // http://www.boost.org/LICENSE_1_0.txt) 10 | 11 | //----------------------------------------------------------// 12 | // // 13 | // クラス名 : shared_array // 14 | // 用 途 : 参照カウント付きスマートポインタの配列版 // 15 | // // 16 | // Version : 1.00 2007/06/22 作成 // 17 | // // 18 | //----------------------------------------------------------// 19 | 20 | 21 | #include // less 22 | 23 | namespace shand { 24 | 25 | template 26 | class shared_array { 27 | Type* object_; // 生のポインタ 28 | int* counter_; // 参照カウンタ 29 | 30 | public: 31 | typedef Type element_type; 32 | typedef Type value_type; 33 | typedef Type* pointer; 34 | 35 | shared_array() 36 | : object_(0), counter_(0) {} 37 | 38 | shared_array(const shared_array& src) 39 | : object_(0), counter_(0) { set(src); } 40 | 41 | explicit shared_array(Type* object) 42 | : object_(object), counter_(new int(1)) {} 43 | 44 | ~shared_array() { release(); } 45 | 46 | // ポインタ取得 47 | Type* get() const { return object_; } 48 | 49 | // 参照カウント取得 50 | long use_count() const 51 | { 52 | if (!counter_) 53 | return 0; 54 | return *counter_; 55 | } 56 | 57 | // 参照先が1つか判断 58 | bool unique() const { return use_count() == 1; } 59 | 60 | shared_array& operator=(const shared_array& rhs) { set(rhs); return *this; } 61 | 62 | Type& operator[](int index) const 63 | { 64 | return object_[index]; 65 | } 66 | 67 | bool operator!() const { return object_ == 0; } 68 | 69 | operator bool() const { return object_ != 0; } 70 | 71 | private: 72 | void set(const shared_array& src) 73 | { 74 | if (this != &src) { 75 | release(); 76 | object_ = src.object_; 77 | counter_ = src.counter_; 78 | 79 | if (counter_ != 0) 80 | ++*counter_; 81 | } 82 | } 83 | 84 | void release() 85 | { 86 | // 参照カウンタを減らす 87 | if (counter_ != 0 && --*counter_ == 0) { 88 | delete[] object_; 89 | delete counter_; 90 | } 91 | object_ = 0; 92 | counter_ = 0; 93 | } 94 | }; 95 | 96 | template 97 | inline bool operator==(shared_array const & lhs, shared_array const & rhs) 98 | { 99 | return lhs.get() == rhs.get(); 100 | } 101 | 102 | template 103 | inline bool operator!=(shared_array const & lhs, shared_array const & rhs) 104 | { 105 | return lhs.get() != rhs.get(); 106 | } 107 | 108 | template 109 | inline bool operator<(shared_array const & lhs, shared_array const & rhs) 110 | { 111 | return std::less()(lhs.get(), rhs.get()); 112 | } 113 | 114 | 115 | } // namespace shand 116 | 117 | #endif // SHAND_SHARED_ARRAY_INCLUDE 118 | 119 | -------------------------------------------------------------------------------- /shand/old/作りかけ/type_list.h: -------------------------------------------------------------------------------- 1 | #ifndef _SHAND_TYPE_LIST_H_ 2 | #define _SHAND_TYPE_LIST_H_ 3 | 4 | struct nil {}; 5 | 6 | template 7 | struct cons { 8 | typedef Car car; 9 | typedef Cdr cdr; 10 | }; 11 | 12 | 13 | #define TYPELIST1(T0) cons 14 | #define TYPELIST2(T0, T1) cons 15 | #define TYPELIST3(T0, T1, T2) cons 16 | #define TYPELIST4(T0, T1, T2, T3) cons 17 | #define TYPELIST5(T0, T1, T2, T3, T4) cons 18 | #define TYPELIST6(T0, T1, T2, T3, T4, T5) cons 19 | #define TYPELIST7(T0, T1, T2, T3, T4, T5, T6) cons 20 | #define TYPELIST8(T0, T1, T2, T3, T4, T5, T6, T7) cons 21 | #define TYPELIST9(T0, T1, T2, T3, T4, T5, T6, T7, T8) cons 22 | #define TYPELIST10(T0,T1, T2, T3, T4, T5, T6, T7, T8, T9) cons 23 | 24 | 25 | 26 | 27 | /* 28 | template 29 | using type_list1 = cons; 30 | 31 | template 32 | using type_list2 = cons>; 33 | 34 | template 35 | using type_list3 = cons>; 36 | 37 | template 38 | using type_list4 = cons>; 39 | 40 | template 41 | using type_list5 = cons>; 42 | 43 | template 44 | using type_list6 = cons>; 45 | 46 | template 47 | using type_list7 = cons>; 48 | 49 | template 50 | using type_list8 = cons>; 51 | 52 | template 53 | using type_list9 = cons>; 54 | 55 | template 56 | using type_list10 = cons>; 57 | */ 58 | 59 | 60 | template 61 | struct nth { 62 | typedef typename nth::type type; 63 | }; 64 | 65 | template 66 | struct nth { 67 | typedef typename TypeList::car type; 68 | }; 69 | 70 | template 71 | struct length { 72 | static const int value = length::value + 1; 73 | }; 74 | 75 | template <> 76 | struct length { 77 | static const int value = 0; 78 | }; 79 | 80 | 81 | #endif // _SHAND_TYPE_LIST_H_ 82 | 83 | -------------------------------------------------------------------------------- /libs/graph/euler_path/test_euler_path.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Akira Takahashi 2012 2 | // Use, modification and distribution is subject to the Boost Software License, 3 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | template 13 | class add_path { 14 | Container& path_; 15 | const Graph& g_; 16 | public: 17 | add_path(Container& path, const Graph& g) : path_(path), g_(g) {} 18 | 19 | template 20 | void operator()(VertexDescriptor v) 21 | { 22 | path_.push_front(get(boost::vertex_index, g_, v)); 23 | } 24 | }; 25 | 26 | struct null_add_path { 27 | template 28 | void operator()(VertexDescriptor) {} 29 | }; 30 | 31 | template 32 | void success_test(const Graph& g, 33 | VertexDescriptor start, 34 | const std::deque& expected) 35 | { 36 | std::deque path; 37 | 38 | add_path, Graph> adder(path, g); 39 | if (!shand::graph::euler_path(g, start, adder)) { 40 | BOOST_TEST(false); 41 | return; 42 | } 43 | 44 | BOOST_TEST(path == expected); 45 | } 46 | 47 | template 48 | void fail_test(const Graph& g, const VertexDescriptor& start) 49 | { 50 | BOOST_TEST(!shand::graph::euler_path(g, start, null_add_path())); 51 | } 52 | 53 | // A 54 | // + 55 | // - - 56 | // B +---------+ C 57 | // | - - | 58 | // | + | 59 | // | - - | 60 | // D +---------+ E 61 | 62 | int main() 63 | { 64 | typedef boost::adjacency_list Graph; 65 | typedef boost::graph_traits::vertex_descriptor vertex_desc; 66 | 67 | enum {A, B, C, D, E, N}; 68 | 69 | // House of Santa 70 | // http://www.mathematische-basteleien.de/house.html 71 | const std::vector > edges = boost::assign::list_of 72 | (std::make_pair(A, B)) 73 | (std::make_pair(B, C)) 74 | (std::make_pair(C, A)) 75 | (std::make_pair(B, D)) 76 | (std::make_pair(B, E)) 77 | (std::make_pair(C, D)) 78 | (std::make_pair(D, E)) 79 | (std::make_pair(E, C)) 80 | ; 81 | 82 | const Graph g(edges.begin(), edges.end(), N); 83 | 84 | { 85 | const std::deque expected = boost::assign::list_of(E)(B)(A)(C)(B)(D)(C)(E)(D); 86 | success_test(g, vertex(E, g), expected); 87 | } 88 | { 89 | const std::deque expected = boost::assign::list_of(D)(B)(A)(C)(B)(E)(D)(C)(E); 90 | success_test(g, vertex(D, g), expected); 91 | } 92 | 93 | fail_test(g, vertex(A, g)); 94 | fail_test(g, vertex(B, g)); 95 | fail_test(g, vertex(C, g)); 96 | 97 | return boost::report_errors(); 98 | } 99 | 100 | -------------------------------------------------------------------------------- /libs/encoding_string/doc/reference/encoding_string/encoding_string.md: -------------------------------------------------------------------------------- 1 | # encoding_stringクラス 2 | 3 | ## 宣言 4 | ```cpp 5 | namespace shand { 6 | 7 | // エンコード文字列 8 | template 9 | class encoding_string; 10 | 11 | } // namespace shand 12 | ``` 13 | 14 | ## 概要 15 | `encoding_string`は、文字コード情報を持つ文字列クラスである。 16 | 17 | [`std::basic_string`][basic_string]が文字型(`char`、`wchar_t`、`char16_t`、`char32_t`)をテンプレートパラメータにとるのに対し、このクラスはテンプレートパラメータとして文字コードの種類を表す型を取る。 18 | 19 | 20 | ## メンバ関数 21 | ### 構築・破棄 22 | 23 | | 名前 | 説明 | 24 | |--------------------------------------------------------|----------------| 25 | | [`(constructor)`](./encoding_string/op_constructor.md) | コンストラクタ | 26 | | `~encoding_string() = default;` | デストラクタ | 27 | 28 | 29 | ### 文字列プロパティ 30 | 31 | | 名前 | 説明 | 32 | |-------------------------------------------|------------------------------------------------| 33 | | [`empty`](./encoding_string/empty.md) | 文字列が空かを判定する | 34 | | [`c_str`](./encoding_string/c_str.md) | C文字列を取得する | 35 | | [`raw_str`](./encoding_string/raw_str.md) | [`basic_string`][basic_string]文字列を取得する | 36 | 37 | 38 | ### コードユニットのインタフェース 39 | 40 | コードユニット(≒ 文字)単位で文字列を操作するインタフェース。結合文字や異体字セレクタは考慮しない。 41 | 42 | システム文字コードは、このインタフェースを持たない。 43 | 44 | | 名前 | 説明 | 45 | |-----------------------------------------------------------|--------------------------------------------------| 46 | | [`codeunit_size`](./encoding_string/codeunit_size.md) | コードユニット数を取得する | 47 | | [`codeunit_at`](./encoding_string/codeunit_at.md) | 任意の位置のコードユニットを取得する | 48 | | [`codeunit_substr`](./encoding_string/codeunit_substr.md) | 部分文字列を取得する | 49 | | [`begin`](./encoding_string/begin.md) | 先頭のコードユニットを指すイテレータを取得する | 50 | | [`end`](./encoding_string/end.md) | 末尾コードユニットの次を指すイテレータを取得する | 51 | 52 | 53 | ## メンバ型 54 | 55 | | 名前 | 説明 | 56 | |------------------|------| 57 | | `char_type` | 文字型。
UTF-8なら`char`、UTF-16なら16ビットの文字型、UTF-32なら32ビットの文字型、システムは`char`。 | 58 | | `string_type` | 内部表現の文字列型で、`raw_str()`メンバ関数の戻り値。`basic_string` | 59 | | `iterator` | コードユニット単位のイテレータ型 | 60 | | `const_iterator` | コードユニット単位の読み取り専用イテレータ型 | 61 | | `value_type` | イテレータの要素型。`encoding_string`。 | 62 | 63 | 64 | ## 例 65 | ```cpp 66 | #include 67 | #include 68 | 69 | int main() 70 | { 71 | using namespace shand; 72 | 73 | const encoding_string s = u8"あいうえお"; 74 | 75 | // 出力ストリーム 76 | std::cout << s << std::endl; // "あいうえお" 77 | 78 | // 部分文字列の取得 79 | std::cout << s.codeunit_substr(2, 3) << std::endl; // "うえお" 80 | std::cout << s.codeunit_substr(2) << std::endl; // "うえお" 81 | 82 | // UTF-8文字もまたUTF-8文字列 83 | encoding_string at = s.codeunit_at(2); 84 | std::cout << at << std::endl; // "う" 85 | } 86 | ``` 87 | 88 | ### 出力 89 | ``` 90 | あいうえお 91 | うえお 92 | うえお 93 | う 94 | ``` 95 | 96 | [basic_string]: https://cpprefjp.github.io/reference/string/basic_string.html 97 | 98 | -------------------------------------------------------------------------------- /shand/angle.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_ANGLE_INCLUDE 2 | #define SHAND_ANGLE_INCLUDE 3 | 4 | // Copyright Akira Takahashi 2014 5 | // Use, modification and distribution is subject to the Boost Software License, 6 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | #include 11 | #include "./strong_typedef/tagged_float.hpp" 12 | 13 | namespace shand { 14 | 15 | struct degree_tag {}; 16 | struct radian_tag {}; 17 | 18 | template 19 | using degree_t = shand::tagged_float; 20 | using degree_f = degree_t; 21 | using degree_d = degree_t; 22 | using degree_ld = degree_t; 23 | 24 | template 25 | using radian_t = shand::tagged_float; 26 | using radian_f = radian_t; 27 | using radian_d = radian_t; 28 | using radian_ld = radian_t; 29 | 30 | namespace detail { 31 | template 32 | void angle_cast_impl(const degree_t& x, radian_t& result) 33 | { 34 | result.get() = 35 | x.get() * boost::math::constants::pi() / static_cast(180.0); 36 | } 37 | 38 | template 39 | void angle_cast_impl(const radian_t& x, degree_t& result) 40 | { 41 | result.get() = 42 | x.get() * static_cast(180.0) / boost::math::constants::pi(); 43 | } 44 | } // namespace detail 45 | 46 | template 47 | ToAngle angle_cast(const FromAngle& x) 48 | { 49 | ToAngle result; 50 | detail::angle_cast_impl(x, result); 51 | return result; 52 | } 53 | 54 | // math functions 55 | template 56 | radian_t sin(const radian_t& x) 57 | { 58 | return radian_t(std::sin(x.get())); 59 | } 60 | 61 | template 62 | radian_t cos(const radian_t& x) 63 | { 64 | return radian_t(std::cos(x.get())); 65 | } 66 | 67 | template 68 | radian_t tan(const radian_t& x) 69 | { 70 | return radian_t(std::tan(x.get())); 71 | } 72 | 73 | template 74 | radian_t asin(const radian_t& x) 75 | { 76 | return radian_t(std::asin(x.get())); 77 | } 78 | 79 | template 80 | radian_t acos(const radian_t& x) 81 | { 82 | return radian_t(std::acos(x.get())); 83 | } 84 | 85 | template 86 | radian_t atan(const radian_t& x) 87 | { 88 | return radian_t(std::atan(x.get())); 89 | } 90 | 91 | template 92 | radian_t atan2(const FloatingPoint& y, 93 | const FloatingPoint& x) 94 | { 95 | return radian_t(std::atan2(y, x)); 96 | } 97 | 98 | } // namespace shand 99 | 100 | #endif // SHAND_ANGLE_INCLUDE 101 | 102 | -------------------------------------------------------------------------------- /shand/encoding_string/normalizer.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_ENCODING_STRING_NORMALIZER_INCLUDE 2 | #define SHAND_ENCODING_STRING_NORMALIZER_INCLUDE 3 | 4 | // Copyright Akira Takahashi 2013 5 | // Use, modification and distribution is subject to the Boost Software License, 6 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | #include 11 | 12 | #if BOOST_OS_WINDOWS 13 | #include 14 | #endif 15 | 16 | namespace shand { 17 | 18 | #if BOOST_OS_WINDOWS 19 | template 20 | encoding_string windows_normalize(::NORM_FORM form, 21 | const encoding_string& src) 22 | { 23 | const encoding_string utf16 = encode(src); 24 | const int length = ::NormalizeString( 25 | form, 26 | utf16.c_str(), 27 | utf16.raw_str().size(), 28 | NULL, 29 | 0); 30 | 31 | std::wstring composed(length, wchar_t()); 32 | if (::NormalizeString( 33 | form, 34 | utf16.c_str(), 35 | utf16.raw_str().size(), 36 | &composed[0], 37 | length) > 0) { 38 | return encode(encoding_string(composed.c_str())); 39 | } 40 | throw std::runtime_error("conversion error"); 41 | } 42 | #endif 43 | 44 | template 45 | class normalizer; 46 | 47 | template <> 48 | class normalizer { 49 | public: 50 | static encoding_string compose(const encoding_string& utf8) 51 | { 52 | if (utf8.empty()) 53 | return utf8; 54 | 55 | #if BOOST_OS_WINDOWS 56 | return windows_normalize(NormalizationC, utf8); 57 | #else 58 | throw std::runtime_error("not implemented"); 59 | #endif 60 | } 61 | 62 | static encoding_string decompose(const encoding_string& utf8) 63 | { 64 | if (utf8.empty()) 65 | return utf8; 66 | 67 | #if BOOST_OS_WINDOWS 68 | return windows_normalize(NormalizationD, utf8); 69 | #else 70 | throw std::runtime_error("not implemented"); 71 | #endif 72 | } 73 | 74 | static encoding_string compatible_compose(const encoding_string& utf8) 75 | { 76 | if (utf8.empty()) 77 | return utf8; 78 | 79 | #if BOOST_OS_WINDOWS 80 | return windows_normalize(NormalizationKC, utf8); 81 | #else 82 | throw std::runtime_error("not implemented"); 83 | #endif 84 | } 85 | 86 | static encoding_string compatible_decompose(const encoding_string& utf8) 87 | { 88 | if (utf8.empty()) 89 | return utf8; 90 | 91 | #if BOOST_OS_WINDOWS 92 | return windows_normalize(NormalizationKD, utf8); 93 | #else 94 | throw std::runtime_error("not implemented"); 95 | #endif 96 | } 97 | }; 98 | 99 | } // namespace shand 100 | 101 | #endif // SHAND_ENCODING_STRING_NORMALIZER_INCLUDE 102 | -------------------------------------------------------------------------------- /libs/encoding_string/utf8_test.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Akira Takahashi 2013 2 | // Use, modification and distribution is subject to the Boost Software License, 3 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | using shand::encoding_string; 13 | namespace encoding = shand::encoding; 14 | 15 | const encoding_string string = u8"あいうえお"; 16 | 17 | void codeunit_size_test() 18 | { 19 | std::size_t codeunit_size = string.codeunit_size(); 20 | BOOST_TEST(codeunit_size == 5); 21 | } 22 | 23 | void codeunit_at_test() 24 | { 25 | encoding_string at = string.codeunit_at(2); 26 | BOOST_TEST(at == encoding_string(u8"う")); 27 | } 28 | 29 | void iteration_test() 30 | { 31 | std::vector> cont; 32 | for (decltype(string)::value_type c : string) { 33 | cont.push_back(c); 34 | } 35 | 36 | const std::vector> expected = { 37 | u8"あ", 38 | u8"い", 39 | u8"う", 40 | u8"え", 41 | u8"お" 42 | }; 43 | 44 | BOOST_TEST(cont == expected); 45 | } 46 | 47 | void ostream_test() 48 | { 49 | std::stringstream ss; 50 | ss << string; 51 | 52 | encoding_string result = ss.str().c_str(); 53 | BOOST_TEST(result == encoding_string("あいうえお")); 54 | } 55 | 56 | void codeunit_substr_range_test() 57 | { 58 | encoding_string sub = string.codeunit_substr(1, 3); 59 | BOOST_TEST(sub == encoding_string(u8"いうえ")); 60 | } 61 | 62 | void codeunit_substr_start_test() 63 | { 64 | encoding_string sub = string.codeunit_substr(2); 65 | BOOST_TEST(sub == encoding_string(u8"うえお")); 66 | } 67 | 68 | void empty_test() 69 | { 70 | BOOST_TEST(!string.empty()); 71 | 72 | encoding_string empty; 73 | BOOST_TEST(empty.empty()); 74 | } 75 | 76 | void bom_test() 77 | { 78 | encoding_string utf8 = u8"\xef\xbb\xbfあいうえお"; 79 | 80 | // not delete BOM 81 | BOOST_TEST(utf8 == encoding_string(u8"\xef\xbb\xbfあいうえお")); 82 | 83 | // ignore BOM 84 | BOOST_TEST(utf8.codeunit_size() == 5); 85 | BOOST_TEST(utf8.codeunit_at(2) == encoding_string(u8"う")); 86 | BOOST_TEST(utf8.codeunit_substr(2) == encoding_string(u8"うえお")); 87 | 88 | std::vector> cont; 89 | for (decltype(string)::value_type c : utf8) { 90 | cont.push_back(c); 91 | } 92 | 93 | const std::vector> expected = { 94 | u8"あ", 95 | u8"い", 96 | u8"う", 97 | u8"え", 98 | u8"お" 99 | }; 100 | 101 | BOOST_TEST(cont == expected); 102 | } 103 | 104 | int main() 105 | { 106 | codeunit_size_test(); 107 | codeunit_at_test(); 108 | iteration_test(); 109 | ostream_test(); 110 | codeunit_substr_range_test(); 111 | codeunit_substr_start_test(); 112 | empty_test(); 113 | bom_test(); 114 | 115 | return boost::report_errors(); 116 | } 117 | 118 | -------------------------------------------------------------------------------- /shand/old/counting.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_COUNTING_INCLUDE 2 | #define SHAND_COUNTING_INCLUDE 3 | 4 | // Copyright Akira Takahashi 2007 5 | // Use, modification and distribution is subject to the Boost Software License, 6 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | //------------------------------------------------------------------// 10 | // // 11 | // 関 数 名 : count_range(int first, int last), zero_to(int last) // 12 | // 用 途 : foreach文用インデックス番号生成 // 13 | // // 14 | // Version : 1.00 2007/10/29 作成 // 15 | // 1.01 2007/11/02 STLアルゴリズムにも適用可にした // 16 | // // 17 | //------------------------------------------------------------------// 18 | 19 | 20 | #include 21 | 22 | namespace shand { 23 | 24 | template 25 | class counting_iterator { 26 | Incrementable value_; 27 | public: 28 | typedef std::random_access_iterator_tag iterator_category; 29 | typedef Incrementable value_type; 30 | typedef Incrementable difference_type; 31 | typedef Incrementable pointer; 32 | typedef Incrementable reference; 33 | 34 | counting_iterator(Incrementable value): value_(value) {} 35 | counting_iterator& operator++ () { ++value_; return *this; } 36 | counting_iterator operator++ (int) { ++value_; return counting_iterator(value_-1); } 37 | Incrementable operator* () const { return value_; } 38 | bool operator== (const counting_iterator& rhs) const { return value_ == rhs.value_; } 39 | bool operator!= (const counting_iterator& rhs) const { return value_ != rhs.value_; } 40 | }; 41 | 42 | template 43 | bool operator<(const counting_iterator& lhs, const counting_iterator& rhs) 44 | { 45 | return *lhs < *rhs; 46 | } 47 | 48 | 49 | template 50 | inline counting_iterator make_counting_iterator(Incrementable count) 51 | { 52 | return counting_iterator(count); 53 | } 54 | 55 | 56 | template 57 | class count_range_t { 58 | counting_iterator first_; 59 | counting_iterator last_; 60 | public: 61 | typedef counting_iterator iterator; 62 | typedef Incrementable reference; 63 | 64 | count_range_t(Incrementable first, Incrementable last) 65 | : first_(first), last_(last) {} 66 | 67 | iterator begin() { return first_; } 68 | iterator end() { return last_; } 69 | const iterator begin() const { return first_; } 70 | const iterator end() const { return last_; } 71 | }; 72 | 73 | 74 | template 75 | inline count_range_t zero_to(Incrementable last) 76 | { 77 | return count_range_t(0, last); 78 | } 79 | 80 | template 81 | inline count_range_t count_range(Incrementable first, Incrementable last) 82 | { 83 | return count_range_t(first, last); 84 | } 85 | 86 | 87 | } // namespace shand 88 | 89 | 90 | //----------------------------------------------------------// 91 | // Sample // 92 | //----------------------------------------------------------// 93 | // vector v; // 94 | // // 95 | // // generate 0〜9 // 96 | // foreach (int index, zero_to(10)) // count_range(0, 10) // 97 | // v.push_back(index); // 98 | // // 99 | //----------------------------------------------------------// 100 | 101 | #endif // SHAND_COUNTING_INCLUDE 102 | 103 | -------------------------------------------------------------------------------- /libs/immutable_vector/test/test.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Akira Takahashi 2014 2 | // Use, modification and distribution is subject to the Boost Software License, 3 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | #include 8 | 9 | shand::vector_builder data() { return {1, 2, 3}; } 10 | 11 | void test_construct() 12 | { 13 | shand::immutable_vector v(data()); 14 | BOOST_TEST(v.get() == data()); 15 | } 16 | 17 | void test_build() 18 | { 19 | shand::immutable_vector v; 20 | v.build(data()); 21 | 22 | BOOST_TEST(v.get() == data()); 23 | } 24 | 25 | void test_iterator() 26 | { 27 | shand::immutable_vector v(data()); 28 | 29 | // pass test 30 | decltype(v)::iterator begin = v.begin(); 31 | decltype(v)::iterator end = v.end(); 32 | BOOST_TEST(end - begin == static_cast(v.size())); 33 | 34 | decltype(v)::const_iterator cbegin = v.cbegin(); 35 | decltype(v)::const_iterator cend = v.cend(); 36 | BOOST_TEST(cend - cbegin == static_cast(v.size())); 37 | } 38 | 39 | void test_size() 40 | { 41 | shand::immutable_vector v(data()); 42 | BOOST_TEST(v.size() == 3u); 43 | } 44 | 45 | void test_empty() 46 | { 47 | shand::immutable_vector v(data()); 48 | BOOST_TEST(!v.empty()); 49 | 50 | shand::immutable_vector e; 51 | BOOST_TEST(e.empty()); 52 | } 53 | 54 | void test_at() 55 | { 56 | shand::immutable_vector v(data()); 57 | 58 | BOOST_TEST(v[0] == 1); 59 | BOOST_TEST(v[1] == 2); 60 | BOOST_TEST(v[2] == 3); 61 | 62 | BOOST_TEST(v.at(0) == 1); 63 | BOOST_TEST(v.at(1) == 2); 64 | BOOST_TEST(v.at(2) == 3); 65 | try { 66 | v.at(3); 67 | BOOST_TEST(false); 68 | } 69 | catch (std::out_of_range&) { 70 | BOOST_TEST(true); 71 | } 72 | 73 | boost::optional front = v.opt_at(0); 74 | BOOST_TEST(front.get() == 1); 75 | 76 | boost::optional center = v.opt_at(1); 77 | BOOST_TEST(center.get() == 2); 78 | 79 | boost::optional back = v.opt_at(2); 80 | BOOST_TEST(back.get() == 3); 81 | 82 | boost::optional out = v.opt_at(3); 83 | BOOST_TEST(out == boost::none); 84 | } 85 | 86 | void test_front() 87 | { 88 | { 89 | shand::immutable_vector v(data()); 90 | boost::optional front = v.opt_front(); 91 | BOOST_TEST(front.get() == 1); 92 | } 93 | { 94 | shand::immutable_vector v; 95 | boost::optional front = v.opt_front(); 96 | BOOST_TEST(front == boost::none); 97 | } 98 | } 99 | 100 | void test_back() 101 | { 102 | { 103 | shand::immutable_vector v(data()); 104 | boost::optional back = v.opt_back(); 105 | BOOST_TEST(back.get() == 3); 106 | } 107 | { 108 | shand::immutable_vector v; 109 | boost::optional back = v.opt_back(); 110 | BOOST_TEST(back == boost::none); 111 | } 112 | } 113 | 114 | void test_data() 115 | { 116 | shand::immutable_vector v(data()); 117 | const int* p = v.data(); 118 | BOOST_TEST(p); 119 | BOOST_TEST(*p == 1); 120 | } 121 | 122 | int main() 123 | { 124 | test_construct(); 125 | test_build(); 126 | test_iterator(); 127 | test_size(); 128 | test_empty(); 129 | test_at(); 130 | test_front(); 131 | test_back(); 132 | test_data(); 133 | 134 | return boost::report_errors(); 135 | } 136 | 137 | -------------------------------------------------------------------------------- /shand/graph/euler_path.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_GRAPH_EULER_PATH_INCLUDE 2 | #define SHAND_GRAPH_EULER_PATH_INCLUDE 3 | 4 | // Copyright Akira Takahashi 2012 5 | // Use, modification and distribution is subject to the Boost Software License, 6 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | namespace shand { namespace graph { 17 | 18 | template 19 | inline bool 20 | has_euler_path(const Graph& g, 21 | typename boost::graph_traits::vertex_descriptor s) 22 | { 23 | typedef boost::graph_traits traits; 24 | typedef typename traits::vertex_descriptor vertex_desc; 25 | typedef typename traits::degree_size_type degree_size_type; 26 | 27 | std::size_t odd = 0; 28 | BOOST_FOREACH (const vertex_desc& v, vertices(g)) { 29 | const degree_size_type size = out_degree(v, g); 30 | if (size % 2 == 1) 31 | ++odd; 32 | } 33 | return (odd == 0 || (odd == 2 && out_degree(s, g) % 2 == 1)); 34 | } 35 | 36 | namespace euler_detail { 37 | 38 | template 39 | inline void visit(const Graph& g, 40 | Matrix& matrix, 41 | typename boost::graph_traits::vertex_descriptor s, 42 | UnaryFunction f, 43 | std::size_t& path_size) 44 | { 45 | typedef typename boost::graph_traits::edge_descriptor edge_desc; 46 | 47 | BOOST_FOREACH (const edge_desc& e, out_edges(s, g)) { 48 | if (matrix[std::make_pair(source(e, g), target(e, g))] >= 0) { 49 | --matrix[std::make_pair(source(e, g), target(e, g))]; 50 | --matrix[std::make_pair(target(e, g), source(e, g))]; 51 | visit(g, matrix, target(e, g), f, path_size); 52 | } 53 | } 54 | f(s); 55 | ++path_size; 56 | } 57 | 58 | // Eulerian tour for undirected graph. 59 | // Implementation use Hierholzer's algorithm. 60 | // Requires : Graph is VertexAndEdgeListGraph 61 | // Complexity : O(E) 62 | // Parameters : `g` is target graph object. 63 | // `s` is start vertex for tour 64 | // `f` is unary function object. the function call when discover vertex. Vertex order is reverse. 65 | // Returns : `true` if find eulerian path, and `false` otherwise. 66 | template 67 | inline bool euler_path(const Graph& g, 68 | typename boost::graph_traits::vertex_descriptor s, 69 | UnaryFunction f, 70 | boost::undirected_tag) 71 | { 72 | BOOST_CONCEPT_ASSERT(( boost::VertexAndEdgeListGraphConcept )); 73 | 74 | if (!has_euler_path(g, s)) 75 | return false; 76 | 77 | typedef typename boost::graph_traits::vertex_descriptor vertex_desc; 78 | std::map, int> matrix; 79 | 80 | std::size_t path_size = 0; 81 | visit(g, matrix, s, f, path_size); 82 | 83 | return path_size == num_edges(g) + 1; 84 | } 85 | 86 | } // namespace euler_detail 87 | 88 | template 89 | inline bool euler_path(const Graph& g, 90 | typename boost::graph_traits::vertex_descriptor s, 91 | UnaryFunction f) 92 | { 93 | typedef typename boost::graph_traits::directed_category Cat; 94 | return euler_detail::euler_path(g, s, f, Cat()); 95 | } 96 | 97 | }} // namespace shand::graph 98 | 99 | #endif // SHAND_GRAPH_EULER_PATH_INCLUDE 100 | 101 | -------------------------------------------------------------------------------- /shand/strong_typedef/tagged_int.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_TAGGED_INT_INCLUDE 2 | #define SHAND_TAGGED_INT_INCLUDE 3 | 4 | // strong typedef for integer types. 5 | // 6 | // Copyright Akira Takahashi 2012-2015. 7 | // Use, modification and distribution is subject to the Boost Software License, 8 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 9 | // http://www.boost.org/LICENSE_1_0.txt) 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #if !defined(BOOST_NO_CXX11_NOEXCEPT) 19 | #define SHAND_NOEXCEPT_COND(cond) noexcept(cond) 20 | #define SHAND_NOEXCEPT_IF(expr) noexcept(noexcept(expr)) 21 | #else 22 | #define SHAND_NOEXCEPT_COND(cond) 23 | #define SHAND_NOEXCEPT_IF(expr) 24 | #endif 25 | 26 | namespace shand { 27 | 28 | template // Tag is phantom type 29 | class tagged_int : 30 | private boost::operators > { 31 | 32 | BOOST_STATIC_ASSERT(boost::is_integral::value); 33 | 34 | Integer value_; 35 | public: 36 | typedef Integer value_type; 37 | 38 | explicit tagged_int(Integer value = 0) 39 | SHAND_NOEXCEPT_COND(boost::has_nothrow_copy_constructor::value) 40 | : value_(value) {} 41 | 42 | Integer& get() BOOST_NOEXCEPT { return value_; } 43 | const Integer& get() const BOOST_NOEXCEPT { return value_; } 44 | 45 | // operators 46 | bool operator<(const tagged_int& x) const SHAND_NOEXCEPT_IF(value_ < x.value_) 47 | { return value_ < x.value_; } 48 | bool operator==(const tagged_int& x) const SHAND_NOEXCEPT_IF(value_ == x.value_) 49 | { return value_ == x.value_; } 50 | 51 | tagged_int& operator+=(const tagged_int& x) SHAND_NOEXCEPT_IF(value_ += x.value_) 52 | { value_ += x.value_; return *this; } 53 | tagged_int& operator-=(const tagged_int& x) SHAND_NOEXCEPT_IF(value_ -= x.value_) 54 | { value_ -= x.value_; return *this; } 55 | tagged_int& operator*=(const tagged_int& x) SHAND_NOEXCEPT_IF(value_ *= x.value_) 56 | { value_ *= x.value_; return *this; } 57 | tagged_int& operator/=(const tagged_int& x) SHAND_NOEXCEPT_IF(value_ /= x.value_) 58 | { value_ /= x.value_; return *this; } 59 | tagged_int& operator%=(const tagged_int& x) SHAND_NOEXCEPT_IF(value_ %= x.value_) 60 | { value_ %= x.value_; return *this; } 61 | 62 | tagged_int& operator&=(const tagged_int& x) SHAND_NOEXCEPT_IF(value_ &= x.value_) 63 | { value_ &= x.value_; return *this; } 64 | tagged_int& operator|=(const tagged_int& x) SHAND_NOEXCEPT_IF(value_ |= x.value_) 65 | { value_ |= x.value_; return *this; } 66 | tagged_int& operator^=(const tagged_int& x) SHAND_NOEXCEPT_IF(value_ ^= x.value_) 67 | { value_ ^= x.value_; return *this; } 68 | 69 | tagged_int& operator++() SHAND_NOEXCEPT_IF(++value_) 70 | { ++value_; return *this; } 71 | tagged_int& operator--() SHAND_NOEXCEPT_IF(--value_) 72 | { --value_; return *this; } 73 | }; 74 | 75 | // Boost hash support 76 | template 77 | std::size_t hash_value(const tagged_int& x) SHAND_NOEXCEPT_IF(boost::hash_value(x.get())) 78 | { 79 | return boost::hash_value(x.get()); 80 | } 81 | 82 | } // namespace shand 83 | 84 | 85 | // Standard hash support 86 | #if !defined(BOOST_NO_CXX11_HDR_FUNCTIONAL) 87 | 88 | namespace std { 89 | 90 | template 91 | struct hash > { 92 | size_t operator()(const shand::tagged_int& x) const BOOST_NOEXCEPT 93 | { 94 | return ::std::hash()(x.get()); 95 | } 96 | }; 97 | 98 | 99 | } // namespace std 100 | 101 | #endif 102 | 103 | #undef SHAND_NOEXEPT_IF 104 | 105 | #endif 106 | 107 | -------------------------------------------------------------------------------- /shand/encoding_string/utf32_string.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_ENCODING_STRING_UTF32_INCLUDE 2 | #define SHAND_ENCODING_STRING_UTF32_INCLUDE 3 | 4 | // Copyright Akira Takahashi 2013 5 | // Use, modification and distribution is subject to the Boost Software License, 6 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | #include 11 | #include 12 | #include "./codeunit_iterator.hpp" 13 | 14 | namespace shand { 15 | 16 | namespace utf32_detail { 17 | 18 | template 19 | std::size_t ignore_bom(const String& data) 20 | { 21 | if (data.size() < 1) 22 | return 0; 23 | 24 | // big endian 25 | if (data[0] == 0x0000feff) 26 | return 1; 27 | 28 | // little endian 29 | if (data[0] == 0xfffe0000) 30 | return 1; 31 | 32 | return 0; 33 | } 34 | 35 | struct bom_skipper { 36 | template 37 | std::size_t operator()(const String& data) const 38 | { 39 | return ignore_bom(data); 40 | } 41 | }; 42 | 43 | struct size_getter { 44 | template 45 | std::size_t operator()(const String& data, std::size_t i) const 46 | { 47 | static_cast(data); 48 | static_cast(i); 49 | return 1; 50 | } 51 | }; 52 | 53 | } // namespace utf32_detail 54 | 55 | template <> 56 | class encoding_string { 57 | public: 58 | #if defined(BOOST_NO_CXX11_CHAR32_T) 59 | using cchar_type = boost::uint32_t; 60 | #else 61 | using cchar_type = char32_t; 62 | #endif 63 | using string_type = std::basic_string; 64 | using value_type = encoding_string; 65 | 66 | using iterator = codeunit_iterator< 67 | string_type, 68 | value_type, 69 | utf32_detail::size_getter, 70 | utf32_detail::bom_skipper>; 71 | using const_iterator = iterator; 72 | 73 | encoding_string() {} 74 | encoding_string(const cchar_type* s) 75 | : data_(s) {} 76 | 77 | std::size_t codeunit_size() const 78 | { return data_.size() - utf32_detail::ignore_bom(data_); } 79 | 80 | encoding_string codeunit_at(std::size_t index) const 81 | { return string_type(1, data_.at(index + utf32_detail::ignore_bom(data_))).c_str(); } 82 | 83 | std::uint32_t codeunit_value_at(std::size_t index) const 84 | { return static_cast(data_.at(index + utf32_detail::ignore_bom(data_))); } 85 | 86 | encoding_string codeunit_substr(std::size_t index, std::size_t codeunit_size) const 87 | { return data_.substr(index + utf32_detail::ignore_bom(data_), codeunit_size).c_str(); } 88 | 89 | encoding_string codeunit_substr(std::size_t index) const 90 | { return data_.substr(index + utf32_detail::ignore_bom(data_)).c_str(); } 91 | 92 | iterator begin() 93 | { return iterator(data_); } 94 | 95 | const_iterator begin() const 96 | { return const_iterator(data_); } 97 | 98 | iterator end() 99 | { return iterator(); } 100 | 101 | const_iterator end() const 102 | { return const_iterator(); } 103 | 104 | const cchar_type* c_str() const 105 | { return data_.c_str(); } 106 | 107 | const string_type& raw_str() const 108 | { return data_; } 109 | 110 | bool empty() const 111 | { return data_.empty(); } 112 | 113 | private: 114 | string_type data_; 115 | }; 116 | 117 | inline bool operator==(const encoding_string& a, const encoding_string& b) 118 | { return a.raw_str() == b.raw_str(); } 119 | 120 | inline bool operator!=(const encoding_string& a, const encoding_string& b) 121 | { return !(a == b); } 122 | 123 | } // namespace shand 124 | 125 | #endif // SHAND_ENCODING_STRING_UTF32_INCLUDE 126 | 127 | -------------------------------------------------------------------------------- /libs/encoding_string/utf32_test.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Akira Takahashi 2013 2 | // Use, modification and distribution is subject to the Boost Software License, 3 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | using shand::encoding_string; 11 | namespace encoding = shand::encoding; 12 | 13 | const encoding_string input = U"あいうえお"; 14 | 15 | void codeunit_size_test() 16 | { 17 | BOOST_TEST(input.raw_str().size() == 5); 18 | BOOST_TEST(input.codeunit_size() == 5); 19 | } 20 | 21 | void codeunit_at_test() 22 | { 23 | const encoding_string at = input.codeunit_at(2); 24 | BOOST_TEST(at == U"う"); 25 | } 26 | 27 | void iteration_test() 28 | { 29 | std::vector> cont; 30 | for (decltype(input)::value_type c : input) { 31 | cont.push_back(c); 32 | } 33 | 34 | const std::vector> expected = { 35 | U"あ", 36 | U"い", 37 | U"う", 38 | U"え", 39 | U"お" 40 | }; 41 | 42 | BOOST_TEST(cont == expected); 43 | } 44 | 45 | void codeunit_substr_range_test() 46 | { 47 | const encoding_string sub = input.codeunit_substr(1, 3); 48 | BOOST_TEST(sub == encoding_string(U"いうえ")); 49 | } 50 | 51 | void codeunit_substr_start_test() 52 | { 53 | const encoding_string sub = input.codeunit_substr(2); 54 | BOOST_TEST(sub == encoding_string(U"うえお")); 55 | } 56 | 57 | void ostream_test() 58 | { 59 | const encoding_string s = U"あいうえお"; 60 | 61 | std::stringstream ss; 62 | ss << s; 63 | 64 | encoding_string result = ss.str().c_str(); 65 | BOOST_TEST(result == encoding_string("あいうえお")); 66 | } 67 | 68 | void empty_test() 69 | { 70 | BOOST_TEST(!input.empty()); 71 | 72 | const encoding_string empty; 73 | BOOST_TEST(empty.empty()); 74 | } 75 | 76 | void bom_test() 77 | { 78 | const std::vector::cchar_type*> literal_list = { 79 | U"あいうえお", // system endian 80 | U"\x0000feffあいうえお", // big endian 81 | U"\xfffe0000あいうえお" // little endian 82 | }; 83 | 84 | const std::vector> utf32_list = { 85 | literal_list[0], 86 | literal_list[1], 87 | literal_list[2] 88 | }; 89 | 90 | for (std::size_t i = 0; i < utf32_list.size(); ++i) { 91 | const auto& literal = literal_list[i]; 92 | const auto& utf32 = utf32_list[i]; 93 | 94 | // not delete BOM 95 | BOOST_TEST(utf32 == encoding_string(literal)); 96 | 97 | // ignore BOM 98 | BOOST_TEST(utf32.codeunit_size() == 5); 99 | BOOST_TEST(utf32.codeunit_at(2) == encoding_string(U"う")); 100 | BOOST_TEST(utf32.codeunit_substr(2) == encoding_string(U"うえお")); 101 | 102 | std::vector> cont; 103 | for (encoding_string::value_type c : utf32) { 104 | cont.push_back(c); 105 | } 106 | 107 | const std::vector> expected = { 108 | U"あ", 109 | U"い", 110 | U"う", 111 | U"え", 112 | U"お" 113 | }; 114 | 115 | BOOST_TEST(cont == expected); 116 | } 117 | } 118 | 119 | int main() 120 | { 121 | codeunit_size_test(); 122 | codeunit_at_test(); 123 | iteration_test(); 124 | codeunit_substr_range_test(); 125 | codeunit_substr_start_test(); 126 | ostream_test(); 127 | empty_test(); 128 | bom_test(); 129 | 130 | return boost::report_errors(); 131 | } 132 | 133 | -------------------------------------------------------------------------------- /shand/graph_literal.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHAND_GRAPH_LITERAL_INCLUDE 2 | #define SHAND_GRAPH_LITERAL_INCLUDE 3 | 4 | // Graph Literal EDSL 5 | // 6 | // Copyright Akira Takahashi 2011 7 | // Use, modification and distribution is subject to the Boost Software License, 8 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 9 | // http://www.boost.org/LICENSE_1_0.txt) 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | namespace shand { 24 | 25 | struct graph_converter { 26 | typedef 27 | boost::multi_index_container< 28 | std::pair, 29 | boost::multi_index::indexed_by< 30 | boost::multi_index::sequenced<>, 31 | boost::multi_index::ordered_unique< 32 | boost::multi_index::identity > 33 | > 34 | > 35 | > 36 | edges_type; 37 | 38 | edges_type edges; 39 | 40 | edges_type::iterator begin() { return edges.begin(); } 41 | edges_type::const_iterator begin() const { return edges.begin(); } 42 | 43 | edges_type::iterator end() { return edges.end(); } 44 | edges_type::const_iterator end() const { return edges.end(); } 45 | 46 | template 47 | operator Container() const 48 | { 49 | return Container(edges.begin(), edges.end(), edges.get<1>().size()); 50 | } 51 | }; 52 | 53 | template 54 | struct is_vertex_type : boost::mpl::false_ {}; 55 | 56 | template 57 | typename boost::lazy_enable_if< 58 | boost::fusion::traits::is_sequence, 59 | boost::fusion::result_of::as_vector< 60 | typename boost::fusion::result_of::push_back::type 61 | > 62 | >::type 63 | operator>=(const Seq& seq, const T& x) 64 | { 65 | return boost::fusion::as_vector(boost::fusion::push_back(seq, x)); 66 | } 67 | 68 | template 69 | typename boost::disable_if< 70 | boost::fusion::traits::is_sequence, 71 | boost::fusion::vector 72 | >::type 73 | operator>=(const T& a, const U& b) 74 | { 75 | return boost::fusion::make_vector(a, b); 76 | } 77 | 78 | template 79 | struct push_backer { 80 | Dest& dest; 81 | 82 | push_backer(Dest& dest) : dest(dest) {} 83 | 84 | template 85 | void operator()(const Seq& seq) const 86 | { 87 | dest.push_back(std::make_pair(boost::fusion::at_c<0>(seq), boost::fusion::at_c<1>(seq))); 88 | } 89 | }; 90 | 91 | template 92 | void vertices_to_edges(const Vertices& vertices, Edges& edges) 93 | { 94 | shand::fusion::adjacency_for_each(vertices, push_backer(edges)); 95 | } 96 | 97 | template 98 | typename boost::enable_if< 99 | boost::fusion::traits::is_sequence, 100 | graph_converter 101 | >::type 102 | operator&(const LSeq& a, const RSeq& b) 103 | { 104 | graph_converter g; 105 | vertices_to_edges(a, g.edges); 106 | vertices_to_edges(b, g.edges); 107 | 108 | return g; 109 | } 110 | 111 | 112 | template 113 | struct vertex_t { 114 | T value; 115 | 116 | typedef T value_type; 117 | 118 | vertex_t() {} 119 | vertex_t(const T& value) : value(value) {} 120 | 121 | operator T() const 122 | { 123 | return value; 124 | } 125 | }; 126 | 127 | template 128 | vertex_t vertex(T x) 129 | { 130 | return vertex_t(x); 131 | } 132 | 133 | template 134 | struct is_vertex_type > : boost::mpl::true_ {}; 135 | 136 | } // namespace shand 137 | 138 | #endif // SHAND_GRAPH_LITERAL_INCLUDE 139 | 140 | -------------------------------------------------------------------------------- /libs/strong_typedef/test_tagged_int.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Akira Takahashi 2012 2 | // Use, modification and distribution is subject to the Boost Software License, 3 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | struct tag {}; 12 | typedef shand::tagged_int integer; 13 | 14 | int main () 15 | { 16 | // initialize 17 | integer x(1); 18 | const integer& cx = x; 19 | 20 | // reference 21 | int& ref = x.get(); 22 | const int& cref = cx.get(); 23 | BOOST_TEST(x == integer(ref)); 24 | BOOST_TEST(x == integer(cref)); 25 | 26 | // relational operators 27 | BOOST_TEST(x == integer(1)); 28 | BOOST_TEST(x != integer(2)); 29 | BOOST_TEST(x < integer(2)); 30 | BOOST_TEST(x <= integer(2)); 31 | BOOST_TEST(x > integer(0)); 32 | BOOST_TEST(x >= integer(0)); 33 | 34 | // add operators 35 | { 36 | integer y(1); 37 | y += integer(2); 38 | BOOST_TEST(y == integer(3)); 39 | 40 | integer z = integer(1) + integer(2); 41 | BOOST_TEST(z == integer(3)); 42 | } 43 | 44 | // subtract operators 45 | { 46 | integer y(3); 47 | y -= integer(1); 48 | BOOST_TEST(y == integer(2)); 49 | 50 | integer z = integer(3) - integer(1); 51 | BOOST_TEST(z == integer(2)); 52 | } 53 | 54 | // multiply operators 55 | { 56 | integer y(3); 57 | y *= integer(2); 58 | BOOST_TEST(y == integer(6)); 59 | 60 | integer z = integer(3) * integer(2); 61 | BOOST_TEST(z == integer(6)); 62 | } 63 | 64 | // divide operators 65 | { 66 | integer y(6); 67 | y /= integer(2); 68 | BOOST_TEST(y == integer(3)); 69 | 70 | integer z = integer(6) / integer(2); 71 | BOOST_TEST(z == integer(3)); 72 | } 73 | 74 | // modulo operators 75 | { 76 | integer y(6); 77 | y %= integer(2); 78 | BOOST_TEST(y == integer(0)); 79 | 80 | integer z = integer(6) % integer(2); 81 | BOOST_TEST(z == integer(0)); 82 | } 83 | 84 | // bit-and operators 85 | { 86 | integer y(0x000B); 87 | y &= integer(0x000E); 88 | BOOST_TEST(y == integer(0x000A)); 89 | 90 | integer z = integer(0x000B) & integer(0x000E); 91 | BOOST_TEST(z == integer(0x000A)); 92 | } 93 | 94 | // bit-or operators 95 | { 96 | integer y(0x000B); 97 | y |= integer(0x000E); 98 | BOOST_TEST(y == integer(0x000F)); 99 | 100 | integer z = integer(0x000B) | integer(0x000E); 101 | BOOST_TEST(z == integer(0x000F)); 102 | } 103 | 104 | // bit-xor operators 105 | { 106 | integer y(0x000B); 107 | y ^= integer(0x000E); 108 | BOOST_TEST(y == integer(0x0005)); 109 | 110 | integer z = integer(0x000B) ^ integer(0x000E); 111 | BOOST_TEST(z == integer(0x0005)); 112 | } 113 | 114 | // increment operators 115 | { 116 | integer y(1); 117 | integer y_prev = y++; 118 | BOOST_TEST(y_prev == integer(1)); 119 | BOOST_TEST(y == integer(2)); 120 | 121 | integer z(1); 122 | integer z_after = ++z; 123 | BOOST_TEST(z_after == integer(2)); 124 | BOOST_TEST(z == integer(2)); 125 | } 126 | 127 | // decrement operators 128 | { 129 | integer y(2); 130 | integer y_prev = y--; 131 | BOOST_TEST(y_prev == integer(2)); 132 | BOOST_TEST(y == integer(1)); 133 | 134 | integer z(2); 135 | integer z_after = --z; 136 | BOOST_TEST(z_after == integer(1)); 137 | BOOST_TEST(z == integer(1)); 138 | } 139 | 140 | // output stream 141 | { 142 | integer y(3); 143 | std::ostringstream ss; 144 | ss << y; 145 | BOOST_TEST(ss.str() == "3"); 146 | } 147 | 148 | // input stream 149 | { 150 | integer y; 151 | std::stringstream ss; 152 | ss << "3"; 153 | ss >> y; 154 | BOOST_TEST(y == integer(3)); 155 | } 156 | 157 | return boost::report_errors(); 158 | } 159 | 160 | --------------------------------------------------------------------------------