6 #include <boost/optional.hpp> 28 template <
typename LabelSet>
32 using value_t = std::pair<typename labelset_t::value_t, bool>;
38 return value_t{labelset_t::special(),
true};
45 return value_t{labelset_t::special(),
false};
48 template <
typename Ls>
50 static std::enable_if_t<Ls::has_one(), bool>
53 return std::get<1>(l) || Ls::is_one(
get_value(l));
56 template <
typename Ls>
58 static std::enable_if_t<!Ls::has_one(), bool>
61 return std::get<1>(l);
68 return is_one_<labelset_t>(l);
71 template <
typename Value>
81 return {ls.transpose(
get_value(l)),
false};
84 template <
typename... Args>
88 return {ls.value(std::forward<Args>(args)...),
false};
92 static typename labelset_t::value_t
95 return std::get<0>(
v);
100 return ls.generators();
105 return ls.pregenerators();
115 template <
typename GenSet>
126 return genset_t::special();
133 return genset_t::one_letter();
143 template <
typename Value>
150 template <
typename... Args>
154 return ls.
value(std::forward<Args>(args)...);
171 return ls.
genset()->pregenerators();
177 template <
typename LabelSet>
189 using word_t =
typename labelset_t::word_t;
206 :
nullableset{std::make_shared<const labelset_t>(ls)}
224 eat(is,
"nullableset<");
225 auto ls = labelset_t::make(is);
235 return this->ls_->open(o);
238 static constexpr
bool 244 static constexpr
bool 250 static constexpr
bool 272 return helper_t::is_one(l);
284 return ls_->genset();
291 return helper_t::generators(*ls_);
298 return helper_t::pregenerators(*ls_);
316 template <
typename LabelSet_>
318 conv(
const LabelSet_& ls,
typename LabelSet_::value_t
v)
const 320 return value(ls_->conv(ls, v));
328 template <
typename... Args>
332 return helper_t::value(*ls_, std::forward<Args>(args)...);
347 -> decltype(labelset_t::letters_of(
v))
349 return labelset_t::letters_of(
v);
356 -> decltype(ls_->letters_of_padded(
v, l))
358 return ls_->letters_of_padded(
v, l);
363 -> decltype(this->letters_of_padded(this->word(
v), l))
365 return letters_of_padded(word(
v), l);
405 raise(*
this,
": mul: invalid arguments: ",
423 if (
auto res = maybe_ldivide(l, r))
426 raise(*
this,
": ldivide: invalid arguments: ",
430 boost::optional<value_t>
448 if (
auto res = maybe_rdivide(l, r))
451 raise(*
this,
": rdivide: invalid arguments: ",
455 boost::optional<value_t>
473 return helper_t::special();
497 return ls_->get_letter(i, quoted);
502 conv(std::istream& i,
bool quoted =
true)
const 505 if (i.good() && i.peek() ==
'\\')
517 return value(ls_->conv(i, quoted));
529 template <
typename Fun>
530 void convs(std::istream& i, Fun&& fun)
const 533 [
this,fun](
const typename labelset_t::value_t& l)
547 ": conjunction: invalid operation (lhs and rhs are not equal): ",
572 template <
typename Value>
587 ls_->print_set(o, fmt);
593 ls_->print_set(o, fmt);
599 ls_->print_set(o, fmt); 612 static typename labelset_t::value_t 613 get_value(const value_t& v) 616 return helper_t::get_value(v); 623 template <typename LabelSet> 624 struct letterized_traits<nullableset<LabelSet>> 626 using traits = letterized_traits<LabelSet>; 627 static constexpr bool is_letterized = traits::is_letterized; 629 using labelset_t = typename traits::labelset_t; 631 static labelset_t labelset(const nullableset<LabelSet>& ls) 633 return make_letterized(*ls.labelset()); 638 template <typename LabelSet> 639 struct nullableset_traits<nullableset<LabelSet>> 641 using type = nullableset<LabelSet>; 642 static type value(const nullableset<LabelSet>& ls) 648 template <typename LabelSet> 649 struct proper_traits<nullableset<LabelSet>> 651 using type = LabelSet; 652 static type value(const nullableset<LabelSet>& ls) 654 return *ls.labelset(); 659 template <typename LabelSet> 660 struct law_traits<nullableset<LabelSet>> 662 using type = law_t<LabelSet>; 663 static type value(const nullableset<LabelSet>& ls) 665 return make_wordset(*ls.labelset()); 674 template <typename LS> 675 struct join_impl<oneset, LS, 676 std::enable_if_t<!LS::has_one()>> 678 using type = nullableset<LS>; 679 static type join(const oneset&, const LS& ls) 686 template <typename LS> 687 struct join_impl<oneset, LS, 688 std::enable_if_t<LS::has_one()>> 691 static type join(const oneset&, const LS& ls) 698 template <typename LS1, typename LS2> 699 struct join_impl<nullableset<LS1>, LS2> 701 using type = std::conditional_t<LS2::has_one(), 703 nullableset<join_t<LS1, LS2>>>; 704 static type join(const nullableset<LS1>& ls1, const LS2& ls2) 706 return {::vcsn::join(*ls1.labelset(), ls2)}; 714 template <typename LS1, typename LS2> 715 struct join_impl<nullableset<LS1>, nullableset<LS2>> 717 using type = nullableset<join_t<LS1, LS2>>; 718 static type join(const nullableset<LS1>& ls1, 719 const nullableset<LS2>& ls2) 721 return {::vcsn::join(*ls1.labelset(), *ls2.labelset())}; 730 #define DEFINE(Lhs, Rhs, Res) \ 731 template <typename GenSet> \ 733 meet(const Lhs& lhs, const Rhs& rhs) \ 735 return {set_intersection(*lhs.genset(), *rhs.genset())}; \ 739 DEFINE(nullableset<letterset<GenSet>>, 740 nullableset<letterset<GenSet>>, nullableset<letterset<GenSet>>); 742 DEFINE(letterset<GenSet>, 743 nullableset<letterset<GenSet>>, nullableset<letterset<GenSet>>); 745 DEFINE(nullableset<letterset<GenSet>>, 746 letterset<GenSet>, nullableset<letterset<GenSet>>); 748 template <typename Lls, typename Rls> 749 nullableset<meet_t<Lls, Rls>> 750 meet(const nullableset<Lls>& lhs, const nullableset<Rls>& rhs) 752 return nullableset<meet_t<Lls, Rls>>{meet(*lhs.labelset(), 764 template <typename LabelSet, 765 typename RandomGenerator = std::default_random_engine> 766 typename nullableset<LabelSet>::value_t 767 random_label(const nullableset<LabelSet>& ls, 768 RandomGenerator& gen = RandomGenerator()) 770 // FIXME: the proportion should be controllable. 771 auto dis = std::bernoulli_distribution(0.5); 772 if (dis(gen) || ls.generators().empty()) 775 return ls.value(random_label(*ls.labelset(), gen)); weightset_mixin< detail::r_impl > r
static Value transpose(const labelset_t &ls, const Value &l)
decltype(ls_->genset()) genset_ptr
Implementation of labels are letters.
static ATTRIBUTE_PURE constexpr value_t special()
typename labelset_t::value_t value_t
static bool less(const value_t &l, const value_t &r)
Whether l < r.
value_t conv(oneset, typename oneset::value_t) const
static ATTRIBUTE_PURE std::enable_if_t<!Ls::has_one(), bool > is_one_(const value_t &l)
decltype(ls_->generators()) genset_t
labelset_ptr ls_
The wrapped LabelSet.
static ATTRIBUTE_PURE constexpr value_t special()
static auto generators(const labelset_t &ls)
bool is_valid(value_t v) const
std::string to_string(direction d)
Conversion to string.
value_t rdivide(const value_t &l, const value_t &r) const
Compute l / r.
static ATTRIBUTE_PURE constexpr value_t one()
static auto generators(const labelset_t &ls)
Print as a parsable type string.
value_t mul(const value_t &l, const value_t &r) const
The concatenation.
law_t< LabelSet > make_wordset(const LabelSet &ls)
The wordset of a labelset.
static auto pregenerators(const labelset_t &ls)
Aut transpose(const transpose_automaton< Aut > &aut)
The transpose of a transpose automaton is the original automaton.
static size_t hash(const value_t &v)
static constexpr bool is_letterized()
auto letters_of_padded(const word_t &v, letter_t l) const -> decltype(ls_->letters_of_padded(v, l))
Prepare to iterate over the letters of v.
bool is_special(const Aut &aut, transition_t_of< Aut > t)
Whether this transition is from pre or to post.
value_t conjunction(const value_t &l, const value_t &r) const
std::ostream & print_set(std::ostream &o, format fmt={}) const
Print labelset description.
static ATTRIBUTE_PURE constexpr value_t one()
std::pair< typename labelset_t::value_t, bool > value_t
typename labelset_t::word_t word_t
std::ostream & print(const value_t &l, std::ostream &o=std::cout, format fmt={}) const
Print label to stream.
auto letters_of_padded(value_t v, letter_t l) const -> decltype(this->letters_of_padded(this->word(v), l))
nullableset(const labelset_ptr &ls)
static value_t value(const labelset_t &ls, Args &&... args)
static bool is_special(const value_t &v)
static ATTRIBUTE_PURE std::enable_if_t< Ls::has_one(), bool > is_one_(const value_t &l)
char eat(std::istream &is, char c)
Check lookahead character and advance.
size_t size(const ExpSet &rs, const typename ExpSet::value_t &r)
genset_ptr genset() const
static Value transpose(const labelset_t &ls, Value l)
static auto letters_of(const word_t &v) -> decltype(labelset_t::letters_of(v))
Prepare to iterate over the letters of v.
value_t lgcd(const value_t &l, const value_t &r) const
The longest common prefix.
value_t conv(const LabelSet_ &ls, typename LabelSet_::value_t v) const
Conversion from another type: first by the wrapped labelset, and then by our wrappers (in case the wr...
ATTRIBUTE_PURE auto transpose(Args &&... args) const -> decltype(this->genset() -> transpose(std::forward< Args >(args)...))
static ATTRIBUTE_PURE bool is_one(const value_t &l)
static bool equal(const value_t &l, const value_t &r)
Whether l == r.
static value_t value(const labelset_t &ls, Args &&... args)
static int compare(const value_t &l, const value_t &r)
Three way comparison between l and r.
static constexpr bool has_one()
nullableset(const labelset_t &ls={})
const labelset_ptr labelset() const
static size_t size(const value_t &v)
boost::optional< value_t > maybe_ldivide(const value_t &l, const value_t &r) const
static nullableset make(std::istream &is)
Build from the description in is.
value_t value(Args &&... args) const
static constexpr bool is_expressionset()
Print as rich UTF-8 text, escaped.
typename helper_t::value_t value_t
constant< type_t::one, Context > one
Add support for an empty word to a LabelSet that does not provide such special label to this end...
word_t word(const value_t &l) const
value_t conv(std::istream &i, bool quoted=true) const
Read a label from a stream.
typename labelset_t::letter_t letter_t
std::shared_ptr< const labelset_t > labelset_ptr
std::enable_if_t<!is_letterized_t< labelset_t_of< Aut > >{}, bool > is_letterized(const Aut &aut)
boost::flyweight< std::string, boost::flyweights::no_tracking, boost::flyweights::intermodule_holder > symbol
An internalized string.
value_t value(Args &&... args) const
Value constructor.
An input/output format for valuesets.
Provide a variadic mul on top of a binary mul(), and one().
static auto pregenerators(const labelset_t &ls)
bool open(bool o) const
Whether unknown letters should be added, or rejected.
bool is_letter(const value_t &v) const
static constexpr bool is_free()
static ATTRIBUTE_PURE value_t get_value(const value_t &v)
Value transpose(const Value &l) const
Mirror label.
Implementation of labels are ones: there is a single instance of label.
void convs(std::istream &i, Fun &&fun) const
Process a label class.
letter_t get_letter(std::istream &i, bool quoted=true) const
static ATTRIBUTE_PURE bool is_one(value_t l)
static ATTRIBUTE_PURE constexpr value_t one()
Implementation of labels are nullables (letter or empty).
boost::optional< value_t > maybe_rdivide(const value_t &l, const value_t &r) const
genset_ptr genset() const
int compare(const Lhs &lhs, const Rhs &rhs)
Comparison between lhs and rhs.
static ATTRIBUTE_PURE labelset_t::value_t get_value(const value_t &v)
static ATTRIBUTE_PURE bool is_one(value_t l)
value_t ldivide(const value_t &l, const value_t &r) const
Compute l \ r = l^{-1}r.
value_t conv(self_t, value_t v) const