diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
commit | 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch) | |
tree | e5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/boost/libs/property_map/example | |
parent | Initial commit. (diff) | |
download | ceph-upstream.tar.xz ceph-upstream.zip |
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/property_map/example')
5 files changed, 167 insertions, 0 deletions
diff --git a/src/boost/libs/property_map/example/Jamfile.v2 b/src/boost/libs/property_map/example/Jamfile.v2 new file mode 100644 index 00000000..928f62a1 --- /dev/null +++ b/src/boost/libs/property_map/example/Jamfile.v2 @@ -0,0 +1,16 @@ +# Boost.PropertyMap Library example Jamfile +# +# Copyright (c) 2018 James E. King III +# +# Distributed under the Boost Software License, Version 1.0. (See accompany- +# ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +import testing ; + +test-suite "property_map-examples" + : [ run compose_property_map_example.cpp ] + [ run example1.cpp ] + [ run example2.cpp ] + [ run example3.cpp ] + ; + diff --git a/src/boost/libs/property_map/example/compose_property_map_example.cpp b/src/boost/libs/property_map/example/compose_property_map_example.cpp new file mode 100644 index 00000000..ed809632 --- /dev/null +++ b/src/boost/libs/property_map/example/compose_property_map_example.cpp @@ -0,0 +1,36 @@ +// Copyright (C) 2013 Eurodecision +// Authors: Guillaume Pinot +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/property_map/compose_property_map.hpp> +#include <iostream> + +int main() +{ + const int idx[] = {2, 0, 4, 1, 3}; + double v[] = {1., 3., 0., 4., 2.}; + boost::compose_property_map<double*, const int*> cpm(v, idx); + + for (int i = 0; i < 5; ++i) + std::cout << get(cpm, i) << " "; + std::cout << std::endl; + + for (int i = 0; i < 5; ++i) + ++cpm[i]; + + for (int i = 0; i < 5; ++i) + std::cout << get(cpm, i) << " "; + std::cout << std::endl; + + for (int i = 0; i < 5; ++i) + put(cpm, i, 42.); + + for (int i = 0; i < 5; ++i) + std::cout << get(cpm, i) << " "; + std::cout << std::endl; + + return 0; +} diff --git a/src/boost/libs/property_map/example/example1.cpp b/src/boost/libs/property_map/example/example1.cpp new file mode 100644 index 00000000..fdaebb19 --- /dev/null +++ b/src/boost/libs/property_map/example/example1.cpp @@ -0,0 +1,48 @@ +// (C) Copyright Jeremy Siek 2002. +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <iostream> +#include <map> +#include <string> +#include <boost/property_map/property_map.hpp> + + +template <typename AddressMap> +void foo(AddressMap address) +{ + typedef typename boost::property_traits<AddressMap>::value_type value_type; + typedef typename boost::property_traits<AddressMap>::key_type key_type; + + value_type old_address, new_address; + key_type fred = "Fred"; + old_address = get(address, fred); + new_address = "384 Fitzpatrick Street"; + put(address, fred, new_address); + + key_type joe = "Joe"; + value_type& joes_address = address[joe]; + joes_address = "325 Cushing Avenue"; +} + +int +main() +{ + std::map<std::string, std::string> name2address; + boost::associative_property_map< std::map<std::string, std::string> > + address_map(name2address); + + name2address.insert(make_pair(std::string("Fred"), + std::string("710 West 13th Street"))); + name2address.insert(make_pair(std::string("Joe"), + std::string("710 West 13th Street"))); + + foo(address_map); + + for (std::map<std::string, std::string>::iterator i = name2address.begin(); + i != name2address.end(); ++i) + std::cout << i->first << ": " << i->second << "\n"; + + return EXIT_SUCCESS; +} diff --git a/src/boost/libs/property_map/example/example2.cpp b/src/boost/libs/property_map/example/example2.cpp new file mode 100644 index 00000000..33402723 --- /dev/null +++ b/src/boost/libs/property_map/example/example2.cpp @@ -0,0 +1,46 @@ +// (C) Copyright Ronald Garcia, Jeremy Siek 2002. +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <iostream> +#include <map> +#include <string> +#include <boost/property_map/property_map.hpp> + + +template <typename ConstAddressMap> +void display(ConstAddressMap address) +{ + typedef typename boost::property_traits<ConstAddressMap>::value_type + value_type; + typedef typename boost::property_traits<ConstAddressMap>::key_type key_type; + + key_type fred = "Fred"; + key_type joe = "Joe"; + + value_type freds_address = get(address, fred); + value_type joes_address = get(address, joe); + + std::cout << fred << ": " << freds_address << "\n" + << joe << ": " << joes_address << "\n"; +} + +int +main() +{ + std::map<std::string, std::string> name2address; + boost::const_associative_property_map< std::map<std::string, std::string> > + address_map(name2address); + + name2address.insert(make_pair(std::string("Fred"), + std::string("710 West 13th Street"))); + name2address.insert(make_pair(std::string("Joe"), + std::string("710 West 13th Street"))); + + display(address_map); + + return EXIT_SUCCESS; +} + + diff --git a/src/boost/libs/property_map/example/example3.cpp b/src/boost/libs/property_map/example/example3.cpp new file mode 100644 index 00000000..2fed1bee --- /dev/null +++ b/src/boost/libs/property_map/example/example3.cpp @@ -0,0 +1,21 @@ +// Copyright Vladimir Prus 2003. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/property_map/vector_property_map.hpp> +#include <string> +#include <iostream> + +int main() +{ + boost::vector_property_map<std::string> m; + + // Assign string to '4'. + m[4] = "e"; + std::cout << "'" << m[4] << "'\n"; + + // Grab string from '10'. Since none is associated, + // "" will be returned. + std::cout << "'" << m[10] << "'\n"; +} |