3 #include <boost/optional.hpp>
4 #include <boost/range/algorithm/find.hpp>
5 #include <boost/range/algorithm/find_if.hpp>
6 #include <boost/range/algorithm/for_each.hpp>
7 #include <boost/range/algorithm_ext/is_sorted.hpp>
21 template <
typename LabelSet>
25 template <
typename LabelSet>
33 template <
typename LabelSet>
34 using one_t = decltype(std::declval<LabelSet>().one());
36 template <
typename LabelSet>
44 #if defined __GNUC__ && !defined __clang__
47 # pragma GCC diagnostic push
48 # pragma GCC diagnostic ignored "-Wsuggest-attribute=noreturn"
52 template <
typename LabelSet>
54 ->
typename LabelSet::value_t
56 return static_if<LabelSet::has_one()>
57 ([](
const auto& ls) {
return ls.one(); },
58 [](
const auto& ls) ->
typename LabelSet::value_t
60 raise(ls,
": does not feature a neutral");
65 #if defined __GNUC__ && !defined __clang__
66 # pragma GCC diagnostic pop
77 template <
typename LabelSet>
85 return std::make_shared<labelset_t>(
labelset_t{ls.genset()});
89 template <
typename LabelSet>
93 template <
typename LabelSet>
97 template <
typename LabelSet>
109 template <
typename Context>
115 template <
typename LabelSet,
typename WeightSet>
135 template <
typename LabelSet,
136 typename Enable =
void>
141 template <
typename LabelSet>
145 template <
typename LabelSet>
156 template <
typename Ctx>
161 template <
typename LabelSet,
typename WeightSet>
180 template <
typename LabelSet>
191 template <
typename LabelSet>
195 template <
typename LabelSet>
207 template <
typename Context>
213 template <
typename LabelSet,
typename WeightSet>
226 template <
typename Context>
232 template <
typename LabelSet,
typename WeightSet>
247 template <
typename ValueSet>
252 template <
typename LabelSet>
256 template <
typename LabelSet>
267 template <
typename Ctx>
272 template <
typename LabelSet,
typename WeightSet>
288 template <
typename LabelSet>
291 const std::vector<typename LabelSet::value_t>& letters,
292 const std::vector<typename LabelSet::value_t>& alphabet,
296 for (
auto it = std::begin(letters), letters_end = std::end(letters);
297 it != letters_end; ++it)
299 auto end = std::mismatch(it, letters_end,
300 boost::range::find(alphabet, *it),
301 alphabet.end()).first;
302 ls.print(*it, out, fmt);
304 auto width = std::distance(it, end);
312 ls.print(*it, out, fmt);
322 template <
typename LabelSet>
325 const std::vector<typename LabelSet::value_t>& letters,
329 using letters_t = std::vector<typename LabelSet::value_t>;
331 auto alphabet = letters_t{};
332 for (
auto l : ls.generators())
333 alphabet.emplace_back(ls.value(l));
341 && 2 * boost::distance(alphabet) < 3 * boost::distance(letters))
345 auto negated = letters_t{};
346 for (
auto l: alphabet)
348 negated.emplace_back(l);
359 template <
typename LabelSet>
360 typename LabelSet::letters_t
378 template <
typename LabelSet,
typename Fun>
382 using letter_t =
typename LabelSet::letter_t;
383 using letters_t =
typename LabelSet::letters_t;
387 auto alphabet = letters_t{};
388 for (
auto l : ls.generators())
396 auto prev = boost::optional<letter_t>{};
397 while (i.peek() != EOF && i.peek() !=
']')
404 ls.sname(),
": letter classes cannot begin with '-'");
406 ls.sname(),
": letter classes cannot finish with '-'");
409 letter_t l2 = ls.get_letter(i);
411 auto gens = ls.generators();
412 auto i = boost::range::find(gens, *prev);
414 if (i != std::end(gens))
417 i != std::end(gens) && *i < l2;
430 letter_t l = ls.get_letter(i);
438 template <
typename LabelSet>
439 typename LabelSet::letters_t
442 using letter_t =
typename LabelSet::letter_t;
443 using letters_t =
typename LabelSet::letters_t;
context< letterized_t< labelset_t_of< Context >>, weightset_t_of< Context >> letterized_context
std::ostream & print_label_ranges_(const LabelSet &ls, const std::vector< typename LabelSet::value_t > &letters, const std::vector< typename LabelSet::value_t > &alphabet, std::ostream &out, format fmt)
Print a set of labels with ranges.
Functor to compare Values of ValueSets.
context< law_t< labelset_t_of< Ctx >>, weightset_t_of< Ctx >> word_context_t
law_t< LabelSet > make_wordset(const LabelSet &ls)
The wordset of a labelset.
letterized_context< context< LabelSet, WeightSet > > make_letterized_context(const context< LabelSet, WeightSet > &c)
The letterized context for c.
auto label_one(const LabelSet &ls) -> typename LabelSet::value_t
Enjoy type inference.
context< nullableset_t< labelset_t_of< Ctx >>, weightset_t_of< Ctx >> nullableset_context_t
typename nullableset_traits< LabelSet >::type nullableset_t
The smallest nullableset that includes LabelSet.
typename proper_traits< LabelSet >::type proper_t
The type of the corresponding proper LabelSet.
auto out(const Aut &aut, state_t_of< Aut > s)
Indexes of visible transitions leaving state s.
letterized_t< LabelSet > make_letterized(const LabelSet &ls)
void require(Bool b, Args &&...args)
If b is not verified, raise an error with args as message.
free_context< context< LabelSet, WeightSet > > make_free_context(const context< LabelSet, WeightSet > &c)
The free context for c.
const weightset_ptr & weightset() const
static constexpr bool is_letterized
context< proper_t< letterized_t< labelset_t_of< Context >>>, weightset_t_of< Context >> free_context
The smallest nullableset which includes LabelSet.
decltype(std::declval< LabelSet >().generators()) generators_mem_fn_t
The type of the LabelSet::generators() member function.
typename letterized_traits< LabelSet >::labelset_t letterized_t
typename law_traits< LabelSet >::type law_t
The smallest wordset that includes LabelSet.
bool_constant< letterized_traits< LabelSet >::is_letterized > is_letterized_t
An input/output format for valuesets.
Container set_difference(const Container &s1, const Container &s2)
The set of members of s1 that are not members of s2.
const labelset_ptr & labelset() const
nullableset_context_t< context< LabelSet, WeightSet > > make_nullableset_context(const context< LabelSet, WeightSet > &ctx)
The nullableset context of a context.
static labelset_t labelset(const labelset_t &ls)
std::ostream & print_label_class(const LabelSet &ls, const std::vector< typename LabelSet::value_t > &letters, std::ostream &out, format fmt)
Print a set of labels (letterized) with classes.
A traits to compute the letterized context.
decltype(std::declval< LabelSet >().one()) one_t
static type value(const LabelSet &ls)
typename detail::weightset_t_of_impl< base_t< ValueSet >>::type weightset_t_of
proper_t< LabelSet > make_proper(const LabelSet &ls)
The corresponding proper LabelSet.
std::integral_constant< bool, B > bool_constant
From a labelset, its non-nullable labelset.
context< proper_t< labelset_t_of< Context >>, weightset_t_of< Context >> proper_context
nullableset_t< LabelSet > make_nullableset(const LabelSet &ls)
The nullableset of a labelset.
word_context_t< context< LabelSet, WeightSet > > make_word_context(const context< LabelSet, WeightSet > &ctx)
The wordset context of a context.
bool none_of_equal(const Range &r, const Value &value)
LabelSet::letters_t conv_label_class_(const LabelSet &ls, std::istream &i)
Read a set of letters (hence, guaranteed in order, and unique).
auto make_proper_context(const context< LabelSet, WeightSet > &ctx) -> proper_context< context< LabelSet, WeightSet >>
From a context, its non-nullable context.