0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-01 03:18:54 +01:00
construct/include/ircd/util/pointers.h

67 lines
1.6 KiB
C
Raw Normal View History

2018-04-25 01:47:19 +02:00
// Matrix Construct
//
// Copyright (C) Matrix Construct Developers, Authors & Contributors
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice is present in all copies. The
// full license for this software is available in the LICENSE file.
#pragma once
#define HAVE_IRCD_UTIL_POINTERS_H
//
// Transform to pointer utils
//
namespace ircd {
namespace util {
/// Transform input sequence values to pointers in the output sequence
/// using two input iterators [begin, end] and one output iterator [begin]
template<class input_begin,
class input_end,
class output_begin>
auto
pointers(input_begin&& ib,
const input_end &ie,
output_begin&& ob)
{
return std::transform(ib, ie, ob, []
(auto&& value)
{
return std::addressof(value);
});
}
/// Transform input sequence values to pointers in the output sequence
/// using two input iterators [begin, end] and one output iterator [begin]
template<class input_begin,
class input_end,
class output_begin,
class output_end>
auto
pointers(input_begin&& ib,
const input_end &ie,
output_begin&& ob,
const output_end &oe)
{
for(; ib != ie && ob != oe; ++ib, ++ob)
*ob = std::addressof(*ib);
return ob;
}
2018-04-25 01:47:19 +02:00
template<class input_container,
class output_container>
auto
pointers(input_container&& ic,
output_container &oc)
{
return pointers(begin(ic), end(ic), begin(oc), end(oc));
2018-04-25 01:47:19 +02:00
}
} // namespace util
} // namespace ircd