contiguous testing in UList output
A list of enum does not get folded into a single uniform entry when printing (since it tests for contiguous)
Activity
- Maintainer
The obvious answer is to define it first:
namespace Foam { template<> inline bool contiguous<extrudeMode>() {return true;} }
which runs as expected.
The real question is if we'd might rather ditch using the globally templated
contiguous()
functions in favour of wrapping it in a compile-time tag struct. Eg,template<class T> struct isContiguous {} ...
probably inheriting from std::is_integral types?
I don't know if there is an easy way to provide a universal overload based on std::is_enum, but could be worth looking at. Might even be able to forward all FixedList sizes etc.
- Author Maintainer
Why is there a contiguous check before printing in compact notation?
- Maintainer
The logic is indeed a bit convoluted, but if we back out the bits not related to the line breaks:
if ( len <= 1 || contiguous<T>() ) { // any single element, or multiple contiguous elements separator = SPACE; } else { // non-contiguous element separator = NEWLINE; }
When writing non-contiguous types that may be short (eg, words) this logic produces loads of newlines, but if the data is something larger (eg, a dictionary) it makes sense.
Now add in logic for line breaks with contiguous data if there would be too many to read properly since we may not want 1 million values on a single line.
if ( len <= 1 || (contiguous<T>() && len <= MAX_PER_LINE) ) { separator = SPACE; }
The additional logic to add is to allow suppression of line breaks:
if ( len <= 1 || (contiguous<T>() && len <= MAX_PER_LINE) || NO_LINE_BREAKS // <- even for non-contiguous ) { separator = SPACE; }
Represent the
NO_LINE_BREAKS
logic byMAX_PER_LINE=0
, which would otherwise be fairly nonsensical:if ( len <= 1 || (contiguous<T>() && len <= MAX_PER_LINE) || !MAX_PER_LINE ) { separator = SPACE; }
Rearrange the logic elements, and you have the result:
if ( len <= 1 || !MAX_PER_LINE || (len <= MAX_PER_LINE && contiguous<T>()) ) { separator = SPACE; }
- Author Maintainer
My issue is with
bool uniform = (len > 1 && contiguous<T>());
Uniform testing&printing should be allowed on all containers that support !=
- Maintainer
Already integrated.
- Mark OLESEN closed
closed