.github
android
build
doc
python
src
android
apple
archive
client
cmdline
command
config
db
decoder
encoder
event
filter
fs
input
io
java
lib
mixer
neighbor
net
output
pcm
player
playlist
protocol
queue
song
sticker
storage
system
tag
thread
time
unix
util
ASCII.hxx
AllocatedArray.hxx
AllocatedString.hxx
BindMethod.hxx
BitReverse.cxx
BitReverse.hxx
ByteOrder.hxx
ByteReverse.cxx
ByteReverse.hxx
Cast.hxx
CharUtil.hxx
CircularBuffer.hxx
Clamp.hxx
Compiler.h
Concepts.hxx
CopyConst.hxx
DeleteDisposer.hxx
DereferenceIterator.hxx
DivideString.cxx
DivideString.hxx
Domain.hxx
DynamicFifoBuffer.hxx
Exception.cxx
Exception.hxx
ForeignFifoBuffer.hxx
GenerateArray.hxx
HexFormat.hxx
HugeAllocator.cxx
HugeAllocator.hxx
IntrusiveForwardList.hxx
IntrusiveHashSet.hxx
IntrusiveHookMode.hxx
IntrusiveList.hxx
IntrusiveSortedList.hxx
IterableSplitString.hxx
LazyRandomEngine.cxx
LazyRandomEngine.hxx
Manual.hxx
Math.hxx
MemberPointer.hxx
MimeType.cxx
MimeType.hxx
NumberParser.cxx
NumberParser.hxx
OffsetPointer.hxx
OptionalCounter.hxx
PeakBuffer.cxx
PeakBuffer.hxx
PrintException.cxx
PrintException.hxx
RecursiveMap.hxx
ReusableArray.hxx
RingBuffer.hxx
ScopeExit.hxx
Serial.cxx
Serial.hxx
ShallowCopy.hxx
SliceBuffer.hxx
SortList.hxx
SpanCast.hxx
SparseBuffer.cxx
SparseBuffer.hxx
SplitString.cxx
SplitString.hxx
StaticFifoBuffer.hxx
StaticVector.hxx
StringAPI.hxx
StringBuffer.hxx
StringCompare.cxx
StringCompare.hxx
StringPointer.hxx
StringSplit.hxx
StringStrip.cxx
StringStrip.hxx
StringUtil.cxx
StringUtil.hxx
TemplateString.hxx
TextFile.hxx
Tokenizer.cxx
Tokenizer.hxx
TransformN.hxx
TruncateString.cxx
TruncateString.hxx
UTF8.cxx
UTF8.hxx
UriExtract.cxx
UriExtract.hxx
UriQueryParser.cxx
UriQueryParser.hxx
UriRelative.cxx
UriRelative.hxx
UriUtil.cxx
UriUtil.hxx
VarSize.hxx
WCharUtil.hxx
WStringAPI.hxx
WStringCompare.cxx
WStringCompare.hxx
format.c
format.h
meson.build
win32
zeroconf
BulkEdit.hxx
Chrono.hxx
CommandLine.cxx
CommandLine.hxx
ConsumeMode.cxx
ConsumeMode.hxx
GitVersion.cxx
GitVersion.hxx
Idle.cxx
Idle.hxx
IdleFlags.cxx
IdleFlags.hxx
Instance.cxx
Instance.hxx
Listen.cxx
Listen.hxx
LocateUri.cxx
LocateUri.hxx
Log.cxx
Log.hxx
LogBackend.cxx
LogBackend.hxx
LogInit.cxx
LogInit.hxx
LogLevel.hxx
Main.cxx
Main.hxx
Mapper.cxx
Mapper.hxx
MusicBuffer.cxx
MusicBuffer.hxx
MusicChunk.cxx
MusicChunk.hxx
MusicChunkPtr.cxx
MusicChunkPtr.hxx
MusicPipe.cxx
MusicPipe.hxx
Partition.cxx
Partition.hxx
Permission.cxx
Permission.hxx
PlaylistDatabase.cxx
PlaylistDatabase.hxx
PlaylistError.cxx
PlaylistError.hxx
PlaylistFile.cxx
PlaylistFile.hxx
PlaylistPrint.cxx
PlaylistPrint.hxx
PlaylistSave.cxx
PlaylistSave.hxx
PluginUnavailable.hxx
RemoteTagCache.cxx
RemoteTagCache.hxx
RemoteTagCacheHandler.hxx
ReplayGainMode.cxx
ReplayGainMode.hxx
SingleMode.cxx
SingleMode.hxx
SongLoader.cxx
SongLoader.hxx
SongPrint.cxx
SongPrint.hxx
SongSave.cxx
SongSave.hxx
SongUpdate.cxx
StateFile.cxx
StateFile.hxx
StateFileConfig.cxx
StateFileConfig.hxx
Stats.cxx
Stats.hxx
TagAny.cxx
TagAny.hxx
TagArchive.cxx
TagArchive.hxx
TagFile.cxx
TagFile.hxx
TagPrint.cxx
TagPrint.hxx
TagSave.cxx
TagSave.hxx
TagStream.cxx
TagStream.hxx
TimePrint.cxx
TimePrint.hxx
ls.cxx
ls.hxx
open.h
subprojects
systemd
test
win32
.clang-format
.gitignore
AUTHORS
COPYING
NEWS
README.md
meson.build
meson_options.txt
mpd.svg
valgrind.suppressions
39 lines
929 B
C++
39 lines
929 B
C++
// SPDX-License-Identifier: BSD-2-Clause
|
|
// author: Max Kellermann <max.kellermann@gmail.com>
|
|
|
|
#ifndef GENERATE_ARRAY_HXX
|
|
#define GENERATE_ARRAY_HXX
|
|
|
|
#include <array>
|
|
#include <utility>
|
|
|
|
template<std::size_t N, typename F, std::size_t... I>
|
|
constexpr auto
|
|
_GenerateArray(F &&f, std::index_sequence<I...>) noexcept
|
|
{
|
|
using T = decltype(f(0));
|
|
|
|
/* double curly braces for compatibility with older compilers
|
|
which are not 100% C++17 compliant (e.g. Apple xcode
|
|
9.4) */
|
|
return std::array<T, N>{{f(I)...}};
|
|
}
|
|
|
|
/**
|
|
* Generate a `constexpr` std::array at compile time by calling the
|
|
* given function for each index.
|
|
*
|
|
* @param N the number of elements in the array
|
|
* @param F the function (called N times with the index as only parameter)
|
|
*/
|
|
template<std::size_t N, typename F>
|
|
constexpr auto
|
|
GenerateArray(F &&f) noexcept
|
|
{
|
|
return _GenerateArray<N>(std::forward<F>(f),
|
|
std::make_index_sequence<N>());
|
|
}
|
|
|
|
#endif
|
|
|