All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros Pages
auction_utils.hpp
Go to the documentation of this file.
1 //=======================================================================
2 // Copyright (c)
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 //=======================================================================
15 #ifndef PAAL_AUCTION_UTILS_HPP
16 #define PAAL_AUCTION_UTILS_HPP
17 
21 
22 #include <boost/range/adaptor/transformed.hpp>
23 #include <boost/range/algorithm/min_element.hpp>
24 #include <boost/range/distance.hpp>
25 #include <boost/range/empty.hpp>
26 
27 #include <utility>
28 
29 namespace paal {
30 namespace auctions {
31 
38 template <class Auction>
39 auto items_number(Auction&& auction) {
40  return boost::distance(auction.template get<items>());
41 }
42 
49 template <class Auction>
50 auto bidders_number(Auction&& auction) {
51  return boost::distance(auction.template get<bidders>());
52 }
53 
60 template <class Auction>
61 typename paal::auctions::auction_traits<Auction>::copies_num_t
62 get_minimum_copies_num(Auction&& auction)
63 {
64  assert(!boost::empty(auction.template get<items>()));
65  using item = typename auction_traits<Auction>::item_t;
66  auto get_copies_num_func = [&](item i)
67  {
68  return auction.template call<get_copies_num>(std::forward<item>(i));
69  };
70  return *min_element_functor(auction.template get<items>(), get_copies_num_func);
71 }
72 
73 }
74 }
75 #endif // PAAL_AUCTION_UTILS_HPP
auto min_element_functor(Range &&range, Functor f)
combination of boost::min_element and boost::adaptors::transformed
auto bidders_number(Auction &&auction)
Returns the number of bidders in an auction.
auto items_number(Auction &&auction)
Returns the number of different kinds of items in an auction.
paal::auctions::auction_traits< Auction >::copies_num_t get_minimum_copies_num(Auction &&auction)
Returns minimum number of copies of an item in an auction.