bool includes(anaset const &subset) const {
		using std::begin;
		using std::end;
		return subset.size() <= size() && std::equal(begin(letters),end(letters),
				           begin(subset.letters),end(subset.letters),
				[](unsigned char l,unsigned char r){ return l>=r;});
	}
Exemplo n.º 2
0
void
ModuleInstance::jump(const Label& label,
					 const CLOCK_INTERNAL_TYPE& elapsedTime,
					 Traial& traial) const
{
#ifndef NDEBUG
	if (!sealed_)
		throw_FigException("this module hasn't been sealed yet");
#endif
	assert(label.is_output());
	const auto iter = transitions_by_label_.find(label.str);
    // Foreign labels and taus won't touch us
    if (!label.is_tau() && end(transitions_by_label_) != iter) {
        const auto& transitions = iter->second;
		for (const Transition& tr: transitions) {
			if (tr.pre(traial.state)) { // If the traial satisfies this precondition
				tr.pos(traial.state);   // apply postcondition to its state
				tr.handle_clocks(       // and update clocks according to it.
					traial,
					begin(lClocks_),
					end(lClocks_),
					firstClock_,
					elapsedTime);
                return;  // At most one transition could've been enabled, trust Raúl
            }
       }
    }
    // No transition was enabled? Then just advance all clocks
	traial.kill_time(firstClock_, num_clocks(), elapsedTime);
}
Exemplo n.º 3
0
void
ModuleInstance::order_transitions()
{
	if (!sealed())
#ifndef NDEBUG
		throw_FigException("this module hasn't been sealed yet");
#else
		return;
#endif

	for (const Transition& tr: transitions_) {
		transitions_by_label_[tr.label().str].emplace_back(tr);
		transitions_by_clock_[tr.triggeringClock].emplace_back(tr);
	}

#ifndef NDEBUG
	for (const auto& vec: transitions_by_clock_)
		for (const Transition& tr1: vec.second)
			if (std::find_if(begin(transitions_), end(transitions_),
							 [&tr1](const Transition& tr2) { return &tr1==&tr2; })
				  == end(transitions_))
				throw_FigException("Transition with label \"" + tr1.label().str
								   + "\" and triggering clock \"" + tr1.triggeringClock
								   + "\" isn't mapped in the clocks list !!!");
	for (const auto& vec: transitions_by_label_)
		for (const Transition& tr1: vec.second)
			if (std::find_if(begin(transitions_), end(transitions_),
							 [&tr1](const Transition& tr2) { return &tr1==&tr2; })
				  == end(transitions_))
				throw_FigException("Transition with label \"" + tr1.label().str
								   + "\" and triggering clock \"" + tr1.triggeringClock
								   + "\" isn't mapped in the labels list !!!");
#endif
}
Exemplo n.º 4
0
const Label&
ModuleInstance::jump(const Traial::Timeout& to,
					 Traial& traial) const
{
#ifndef NDEBUG
	if (!sealed_)
		throw_FigException("this module hasn't been sealed yet");
#endif
	const float elapsedTime(to.value);
	const auto iter = transitions_by_clock_.find(to.name);
	assert(end(transitions_by_clock_) != iter);  // deny foreign clocks
	traial.kill_time(to.gpos, 1ul, 100.0f);      // mark this clock 'expired'
	const auto& transitions = iter->second;
	for (const Transition& tr: transitions) {
		if (tr.pre(traial.state)) { // If the traial satisfies this precondition
			tr.pos(traial.state);   // apply postcondition to its state
			tr.handle_clocks(       // and update clocks according to it.
				traial,
				begin(lClocks_),
				end(lClocks_),
				firstClock_,
				elapsedTime);
            // Finally broadcast the output label triggered
			assert(tr.label().is_output());
			return tr.label();
		}
	}
    // No transition was enabled => advance all clocks and broadcast tau
	traial.kill_time(firstClock_, num_clocks(), elapsedTime);
	return TAU;
}
Exemplo n.º 5
0
int main()
{
    // instantiates int compare(const int&, const int&)
    cout << compare(1, 0) << endl;       // T is int

    // instantiates int compare(const vector<int>&, const vector<int>&)
#ifdef LIST_INIT
    vector<int> vec1{1, 2, 3}, vec2{4, 5, 6};
#else
    int temp1[] = {1, 2, 3}, temp2[] = {4, 5, 6};
    vector<int> vec1(begin(temp1), end(temp1)), 
	            vec2(begin(temp2), end(temp2));
#endif
    cout << compare(vec1, vec2) << endl; // T is vector<int>

    long l1, l2;
    int i1, i2;
    compare(i1, i2);      // instantiate compare(int, int)
    compare(l1, l2);      // instantiate compare(long, long)
	compare<int>(i1, l2); // uses compare(int, int)
	compare<long>(i1, l2);// uses compare(long, long)

    const char *cp1 = "hi", *cp2 = "world";
    compare(cp1, cp2);          // calls the specialization
    compare<string>(cp1, cp2);  // converts arguments to string

    return 0;
}
Exemplo n.º 6
0
void
check ()
{
  using std::begin;
  using std::end;

  // Initialize the container with a base sequence.
  T seq{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };

  // Construct a random generator over the range.
  auto gen = quantify_over_range (seq);

  // Check that element in the generate range is in the originating vector.
  for (int i = 0; i < 10; ++i)
    {
      auto r = gen ();
      auto first = begin (r);
      auto last = end (r);

      // From the first iterator i where *i == *first, the sequences
      // [first, last) and [i, i + last - first) compare equal.
      if (first != last)
        {
          auto i = find (begin (seq), end (seq), *first);
          assert (equal (first, last, i));
        }
    }
}
Exemplo n.º 7
0
int main()
{
	int ia[3][4] = {0,0,0,0,0,0,0,0,0,0,0,0};
	// 这里需要注意2维数组,需要使用引用方可使用代范围的for循环
	for(int (&i)[4]:(ia))
	{
		for(int j:i)	
		{
			cout << j << " ";
		}
		cout << endl;
	}
	cout << "---------------"<< endl;
	for(int i = 0; i < 3; i++ )
	{
		int *p = ia[i];	
		for(int j = 0; j < 4; j++)
		{
			cout << p[j] << " ";	
		}
		cout << endl;
	}
	cout << "----------------" << endl;
	for(int (*i)[4] = begin(ia); i != end(ia) ; i++)
	{
		for(int *j = begin(*i); j != end(*i); j++)
		{
			cout << *j << " ";	
		}
		cout << endl;
	}
	cout << "----------------" << endl;
	return 0;
}
Exemplo n.º 8
0
int main()
{
	int ia[3][4] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
	for(int (&row)[4]:ia) // Range for need to use for outfor & instead of *.
	{
		for(int col: row)
		{
			cout << col << "  ";
		}
	}
	cout << endl;

	// Traditional for using index.
	for(int i = 0; i < 3; ++i)
	{
		for(int j = 0; j < 4; ++j)
		{
			cout << ia[i][j] << "  ";
		}
	}
	cout << endl;

	// Traditional for using pointer.
	for(int (* row) [4] = begin(ia); row != end(ia); ++row)
	{
		for(int * col = begin(*row); col != end(*row); ++ col)
		{
			cout << * col << "  ";
		}
	}
	cout << endl;
	return(0);
}
Exemplo n.º 9
0
void CheckEqualRange(const Range1& r1, const Range2& r2)
{
    using std::begin;
    using std::end;

    CheckEqualRange(begin(r1), end(r1), begin(r2), end(r2));
}
Exemplo n.º 10
0
void bayesian_kriging_test::test_build_covariance_matrices() {
	Parameter params;
	const point_timeaxis time_axis(ctimes);
	SourceList sources;
	DestinationList destinations;
	build_sources_and_dests(3, 3, 15, 15, 2, 10, time_axis, false, sources, destinations);
	arma::mat K, k;
	utils::build_covariance_matrices(begin(sources), end(sources), begin(destinations), end(destinations), params, K, k);
	TS_ASSERT_EQUALS(K.n_rows, (size_t)9);
	TS_ASSERT_EQUALS(K.n_cols, (size_t)9);
    for (size_t i = 0;i < 3;++i) {
        TS_ASSERT_DELTA(K(i, i), params.sill() - params.nug(), 0.00001);
    }
    // verify symmetry
    for (size_t r = 0;r < 3;++r) {
        for (size_t c = 0;c < 3;++c) {
            TS_ASSERT_DELTA(K(r, c), K(c, r), 1e-9);
        }
    }
    // verify two off diagnoal values
    TS_ASSERT_DELTA(K(0, 1), 2.011082466, 1e-6);
    TS_ASSERT_DELTA(K(0, 2), 0.165079701, 1e-6);
    // verify size of the other matrix
	TS_ASSERT_EQUALS(k.n_rows, (size_t)9);
	TS_ASSERT_EQUALS(k.n_cols, (size_t)15 * 15);
}
Exemplo n.º 11
0
void Tunnel::stop()
{
  auto d = Tunnel::_instance->d_func();

  auto stopDispatcherFunc =
    [](TunnelPrivate::DispatcherMap::value_type& pair)
  {
    winfo("Stopping the " + pair.second->name() + " dispatcher...");
    assert(pair.second);
    pair.second->stop();
    winfo("Stopped the " + pair.second->name() + " dispatcher.");
  };
  auto stopReceiverFunc =
    [](TunnelPrivate::ReceiverMap::value_type& pair)
  {
    winfo("Stopping the " + pair.second->name() + " receiver...");
    assert(pair.second);
    pair.second->stop();
    winfo("Stopped the " + pair.second->name() + " receiver.");
  };

  wdebug("Stopping the Tunnel...");
  for_each(begin(d->receivers), end(d->receivers), stopReceiverFunc);
  for_each(begin(d->dispatchers), end(d->dispatchers), stopDispatcherFunc);

  instance()->emitEvent(make_shared<Events::Event>(W_EVENT_TUNNEL_STOP));

  wdebug("Stopped the Tunnel.");
}
Exemplo n.º 12
0
void filtering_kbd_input(uint32_t uchar, Utf8CharFn utf32_char_fn, NoPrintableFn no_printable_fn)
{
    constexpr struct {
        uint32_t uchar;
        array_view_const_char str;
        // for std::sort and std::lower_bound
        operator uint32_t () const { return this->uchar; }
    } noprintable_table[] = {
        {0x00000008, cstr_array_view("/<backspace>")},
        {0x00000009, cstr_array_view("/<tab>")},
        {0x0000000D, cstr_array_view("/<enter>")},
        {0x0000001B, cstr_array_view("/<escape>")},
        {0x0000007F, cstr_array_view("/<delete>")},
        {0x00002190, cstr_array_view("/<left>")},
        {0x00002191, cstr_array_view("/<up>")},
        {0x00002192, cstr_array_view("/<right>")},
        {0x00002193, cstr_array_view("/<down>")},
        {0x00002196, cstr_array_view("/<home>")},
        {0x00002198, cstr_array_view("/<end>")},
    };
    using std::begin;
    using std::end;
    // TODO used static_assert
    assert(std::is_sorted(begin(noprintable_table), end(noprintable_table)));

    auto p = std::lower_bound(begin(noprintable_table), end(noprintable_table), uchar);
    if (p != end(noprintable_table) && *p == uchar) {
        no_printable_fn(p->str);
    }
    else {
        utf32_char_fn(uchar);
    }
}
Exemplo n.º 13
0
void Tunnel::start()
{
  W_SPRV(Tunnel);
  auto startDispatcherFunc =
    [](std::pair<const string, Tunnel::Dispatcher::Ptr> pair)
  {
    winfo("Starting the " + pair.second->name() + " dispatcher...");
    assert(pair.second);
    pair.second->start();
    winfo("Started the " + pair.second->name() + " dispatcher.");
  };
  auto startReceiverFunc =
    [](std::pair<const string, Tunnel::Receiver::Ptr> pair)
  {
    winfo("Starting the " + pair.second->name() + " receiver...");
    assert(pair.second);
    pair.second->start();
    winfo("Started the " + pair.second->name() + " receiver.");
  };

  wdebug("Starting the Tunnel...");
  for_each(begin(d->receivers), end(d->receivers), startReceiverFunc);
  for_each(begin(d->dispatchers), end(d->dispatchers), startDispatcherFunc);

  auto eventPtr = make_shared<Events::Event>(W_EVENT_TUNNEL_START);
  assert(instance()->emitter());
  instance()->emitEvent(eventPtr);

  wdebug("Started the Tunnel.");
}
Exemplo n.º 14
0
int main()
{
	int ia[3][4] = {
		{ 0, 1, 2, 3 },
		{ 4, 5, 6, 7 },
		{ 8, 9, 10, 11 }
	};

	/* range for */
	for (auto rows : ia)
		for (auto number : rows)
			cout << number << " ";
	cout << endl;

	/* sub */
	for (auto i = 0; i != 3; ++i)
		for (auto j = 0; j != 4; ++j)
			cout << ia[i][j] << " ";
	cout << endl;

	/* pointer */
	for (auto pRow = begin(ia); pRow != end(ia); ++pRow)
		for (auto pCol = begin(*pRow); pCol != end(*pRow); ++pCol)
			cout << *pCol << " ";
	cout << endl;

	return 0;
}
Exemplo n.º 15
0
LanguageButton::LanguageButton(
    std::string const & enable_locales,
    Widget & parent,
    gdi::GraphicApi & drawable,
    FrontAPI & front,
    Font const & font,
    Theme const & theme
)
    : WidgetFlatButton(drawable, *this, this, nullptr, -1,
                       theme.global.fgcolor, theme.global.bgcolor,
                       theme.global.focus_color, 2, font, 7, 7)
    , front(front)
    , parent(parent)
{
    using std::begin;
    using std::end;

    auto LCID = front.get_keylayout();

    {
        auto const keylayouts = Keymap2::keylayouts();
        auto const it = std::find_if(begin(keylayouts), end(keylayouts), [&](Keylayout const * k){
            return k->LCID == LCID;
        });
        if (it == end(keylayouts)) {
            auto & default_layout = Keymap2::default_layout();
            LCID = default_layout.LCID;
            this->locales.push_back({default_layout.locale_name, default_layout.LCID});
        }
        else {
            this->locales.push_back({(*it)->locale_name, (*it)->LCID});
        }
    }


    for (auto && r : get_split(enable_locales, ',')) {
        auto const trimmed_range = trim(r);
        auto cstr = begin(trimmed_range).base();
        auto cend = end(trimmed_range).base();

        auto const keylayouts = Keymap2::keylayouts();
        auto const it = std::find_if(begin(keylayouts), end(keylayouts), [&](Keylayout const * k){
            return strncmp(k->locale_name, cstr, cend-cstr) == 0;
        });
        if (it != end(keylayouts)) {
            if ((*it)->LCID != LCID) {
                this->locales.push_back({(*it)->locale_name, (*it)->LCID});
            }
        }
        else {
            LOG(LOG_WARNING, "Layout \"%.*s\" not found.", static_cast<int>(cend - cstr), cstr);
        }
    }

    this->set_text(this->locales[0].locale_name);

    Dimension dim = this->get_optimal_dim();
    this->set_wh(dim);
}
Exemplo n.º 16
0
inline Iterator_type<R1> 
find_first_of(R1&& range1, R2&& range2)
{
  using std::begin;
  using std::end;
  return std::find_first_of(begin(range1), end(range1), 
                            begin(range2), end(range2));
}
Exemplo n.º 17
0
inline Iterator_type<R1> 
find_end(R1&& range1, R2&& range2, C comp)
{
  using std::begin;
  using std::end;
  return std::find_end(begin(range1), end(range1), 
                       begin(range2), end(range2), comp);
}
Exemplo n.º 18
0
 void reset() {
     using std::begin;
     using std::end;
     std::fill(begin(numEntriesCache), end(numEntriesCache), 0);
     std::fill(begin(totalEntriesCache), end(totalEntriesCache), 0);
     this->bBitMask = 0;
     ::memset(entries, 0, sizeof(entries));
 }
Exemplo n.º 19
0
int main()
{
    vector<int> v1(3, 43), v2(10);
    Blob<int> a1(v1.begin(), v1.end()),
#ifdef INITIALIZER_LIST
         a2 = {0,1,2,3,4,5,6,7,8,9},
#endif
         a3(v2.begin(), v2.end());
#ifndef INITIALIZER_LIST
    int temp[] = {0,1,2,3,4,5,6,7,8,9};
    Blob<int> a2(begin(temp), end(temp));
#endif

    cout << a1 << "\n\n" << a2 << "\n\n" << a3 << endl;

    cout << "\ncopy" << "\n\n";
    Blob<int> a5(a1);
    cout << a5 << endl;

    cout << "\nassignment" << "\n\n";

    a1 = a3;
    cout << a1 << "\n\n" << a2 << "\n\n" << a3 << endl;

    cout << "\nelement assignment" << "\n\n";
    a1[0] = 42;
    a1[a1.size() - 1] = 15;
    cout << a1 << "\n\n" << a3 << endl;

#ifdef INITIALIZER_LIST
    Blob<string> s1 = {"hi", "bye", "now"};
#else
    string temp2[] = {"hi", "bye", "now"};
    Blob<string> s1(begin(temp2), end(temp2));
#endif
    BlobPtr<string> p(s1);    // p points to the vector inside s1
    *p = "okay";                 // assigns to the first element in s1
    cout << p->size() << endl;   // prints 4, the size of the first element in s1
    cout << (*p).size() << endl; // equivalent to p->size()

#ifdef INITIALIZER_LIST
    Blob<string> s2 {"one", "two", "three"};
#else
    string temp3[] = {"one", "two", "three"};
    Blob<string> s2(begin(temp3), end(temp3));
#endif
    // run the string empty function in the first element in s2
    if (s2[0].empty())
        s2[0] = "empty"; // assign a new value to the first string in s2

    cout << a1 << endl;
    cout << a2 << endl;
    a2.swap(a1);
    cout << a1 << endl;
    cout << a2 << endl;

    return 0;
}
size_t test__intrusive_containers()
{
    CPPA_TEST(test__intrusive_containers);
    iint_list ilist1;
    ilist1.push_back(new iint(1));
    ilist1.emplace_back(2);
    ilist1.push_back(new iint(3));
    {
        iint_list tmp;
        tmp.push_back(new iint(4));
        tmp.push_back(new iint(5));
        ilist1.splice_after(ilist1.before_end(), std::move(tmp));
        CPPA_CHECK(tmp.empty());
    }
    int iarr1[] = { 1, 2, 3, 4, 5 };
    CPPA_CHECK((std::equal(begin(iarr1), end(iarr1), begin(ilist1))));
    CPPA_CHECK((std::equal(begin(ilist1), end(ilist1), begin(iarr1))));

    ilist1.push_front(new iint(0));
    auto i = ilist1.erase_after(ilist1.begin());
    // i points to second element
    CPPA_CHECK_EQUAL(i->value, 2);
    i = ilist1.insert_after(i, new iint(20));
    CPPA_CHECK_EQUAL(i->value, 20);
    int iarr2[] = { 0, 2, 20, 3, 4, 5 };
    CPPA_CHECK((std::equal(begin(iarr2), end(iarr2), begin(ilist1))));

    auto p = ilist1.take();
    CPPA_CHECK(ilist1.empty());
    auto ilist2 = iint_list::from(p);
    ilist2.emplace_front(1);                    // 1 0 2 20 3 4 5
    i = ilist2.erase_after(ilist2.begin());     // 1 2 20 3 4 5
    CPPA_CHECK_EQUAL(i->value, 2);
    ilist2.erase_after(i);                      // 1 2 3 4 5
    CPPA_CHECK((std::equal(begin(iarr1), end(iarr1), begin(ilist2))));

    // five elements + two dummies
    CPPA_CHECK_EQUAL(s_iint_instances, 7);

    ilist2.remove_if([](iint const& val) { return (val.value % 2) != 0; });

    // two elements + two dummies
    CPPA_CHECK_EQUAL(s_iint_instances, 4);

    int iarr3[] = { 2, 4 };
    CPPA_CHECK((std::equal(begin(iarr3), end(iarr3), begin(ilist2))));

    auto x = ilist2.take_after(ilist2.before_begin());
    CPPA_CHECK_EQUAL(x->value, 2);
    delete x;

    ilist2.clear();
    // two dummies
    CPPA_CHECK_EQUAL(s_iint_instances, 2);
    CPPA_CHECK(ilist2.empty());

    return CPPA_TEST_RESULT;
}
	std::string operator-(anaset const &subset) const {
		using std::begin;
		using std::end;
		std::string res{};
		std::equal(begin(letters),end(letters),
			       begin(subset.letters),end(subset.letters),
				   [&res,c='a'](unsigned char l, unsigned char r)mutable
				   { res.append(l-r,c++); return true;});
		return res;
	}
Exemplo n.º 22
0
LandmarkCollection<T> filter(const LandmarkCollection<T>& landmarks, const std::vector<std::string>& filter)
{
	LandmarkCollection<T> filtered_landmarks;
	using std::begin;
	using std::end;
	std::copy_if(begin(landmarks), end(landmarks), std::back_inserter(filtered_landmarks),
		[&](const Landmark<T>& lm) { return std::find(begin(filter), end(filter), lm.name) != end(filter); }
	);
	return filtered_landmarks;
};
Exemplo n.º 23
0
inline bool
ends_with(const _tRange1& input, const _tRange2& test, _fPred comp)
{
	using std::begin;
	using std::end;

	return details::ends_with_iter_dispatch(begin(input), end(input),
		begin(test), end(test), comp, typename std::iterator_traits<
		remove_reference_t<decltype(begin(input))>>::iterator_category());
}
Exemplo n.º 24
0
bool
ModuleInstance::is_our_clock(const std::string& clockName) const
{
	if (clockName.empty())
		return true;
	auto clockFound = std::find_if(begin(lClocks_),
								   end(lClocks_),
								   [&] (const Clock& clk)
								   { return clockName == clk.name(); });
	return end(lClocks_) != clockFound;
}
Exemplo n.º 25
0
 static bool apply_enum(std::string const & str_tname, Fn fn, std::vector<E> const & values)
 {
     auto p = std::find_if(begin(values), end(values), [&str_tname](auto & value){
         return str_tname == value.name;
     });
     if (p != end(values)) {
         fn(*p);
         return true;
     }
     return false;
 }
void printCandidate(std::ostream & out,anacand const & cand){
	// should create all permutations of cand's words
	std::vector<std::string> sentence{};

	transform(begin(cand),end(cand),back_inserter(sentence),[](anaword w){
		std::string word{};
		transform(begin(w.second),end(w.second),back_inserter(word),tolower);
		return word;
	});
	copy(begin(sentence),end(sentence),outiter{out," "});
	out << '\n';
}
Exemplo n.º 27
0
void CompilationUnit::pushPrivateFlags(std::string flags)
{
    auto newFlags = shlex(flags);

    // if the new flags contain anything new then we push the whole
    // lot (this is needed because we are running with a single pass
    // linker)
    if (std::search(begin(_flags), end(_flags),
		    begin(newFlags), end(newFlags)) == end(_flags))
        for (auto& flag : newFlags)
            _privateFlags.push_back(std::move(flag));
}
Exemplo n.º 28
0
int main()
{
    int arr1[3] = { 0, 1, 2};
    int arr2[3] = { 0, 1, 2};

    if (compare(begin(arr1), end(arr1), begin(arr2), end(arr2)))
        cout << "The two arrays are equal." << endl;
    else
        cout << "The two arrays are not equal." << endl;


}
Exemplo n.º 29
0
int main()
{
    int i = 0, j[2] = {0, 1};
    char ch[5] = "pezy";
    
    print(ch);
    print(begin(j), end(j));
    print(&i);
    print(j, end(j)-begin(j));
    print(j);
    
    return 0;
}
Exemplo n.º 30
0
void bayesian_kriging_test::test_build_elevation_matrices() {
	Parameter params;
	const point_timeaxis time_axis(ctimes);
	SourceList sources;
	DestinationList destinations;
	build_sources_and_dests(3, 3, 15, 15, 2, 10, time_axis, false, sources, destinations);
	arma::mat S_e, D_e;
	utils::build_elevation_matrices(begin(sources), end(sources), begin(destinations), end(destinations), S_e, D_e);
	TS_ASSERT_EQUALS(S_e.n_cols, (size_t)2);
	TS_ASSERT_EQUALS(S_e.n_rows, (size_t)9);
	TS_ASSERT_EQUALS(D_e.n_cols, (size_t)15 * 15);
	TS_ASSERT_EQUALS(D_e.n_rows, (size_t)2);
}