forked from Alepha/Alepha
61 lines
1.6 KiB
C++
61 lines
1.6 KiB
C++
static_assert( __cplusplus > 2020'99 );
|
|
|
|
#pragma once
|
|
|
|
#include <Alepha/Alepha.h>
|
|
|
|
#include <ostream>
|
|
|
|
#include <Alepha/Capabilities.h>
|
|
#include <Alepha/template_for.h>
|
|
#include <Alepha/string_algorithms.h>
|
|
#include <Alepha/delimited_list.h>
|
|
#include <Alepha/Concepts.h>
|
|
|
|
#include <Alepha/Reflection/tuplizeAggregate.h>
|
|
|
|
#include <Alepha/IOStreams/delimiters.h>
|
|
|
|
namespace Alepha::Hydrogen::IOStreams ::detail:: OStreamable_m
|
|
{
|
|
inline namespace exports
|
|
{
|
|
struct OStreamable {};
|
|
}
|
|
|
|
template< typename T >
|
|
concept OStreamableAggregate= Aggregate< T >
|
|
// For now, this part seems to have problems, since the `has_capability` function
|
|
// is either broken... or gcc has a bug which prevents it from functioning
|
|
// correctly.
|
|
//
|
|
// Therefore, we just allow the aggregate case, for the moment. Which is the
|
|
// most common case, anyhow.
|
|
//and Capability< T, OStreamable >
|
|
;
|
|
|
|
template< OStreamableAggregate Agg >
|
|
std::ostream &
|
|
operator << ( std::ostream &os, Agg &ostreamable )
|
|
{
|
|
const auto decomposed= Alepha::Reflection::tuplizeAggregate( ostreamable );
|
|
//static_assert( Capability< Agg, exports::OStreamable > );
|
|
auto delim= adaptStream( StartDelimitedList{ []( std::ostream &os ) { os << fieldDelimiter; } }, os );
|
|
|
|
|
|
// TODO: Consider the lens system here... but the basic use case seems to be for
|
|
// aggregates, so we'll go with this simple case for now...
|
|
template_for( decomposed ) <=[&]( const auto &element )
|
|
{
|
|
os << NextItem << element;
|
|
};
|
|
|
|
return os;
|
|
}
|
|
}
|
|
|
|
namespace Alepha::Hydrogen::IOStreams::inline exports::inline OStreamable_m
|
|
{
|
|
using namespace detail::OStreamable_m::exports;
|
|
}
|