Пример #1
0
 bool any_of(const std::string& key, std::initializer_list<T> list) const {
     std::unordered_map<std::string, double>::const_iterator it = _opt.find(key);
     return (it != _opt.cend() && std::any_of(list.begin(), list.end(), [&](const T& t) { return t == static_cast<T>(it->second); }));
 }
Пример #2
0
AppInitializer::AppInitializer(std::initializer_list<int> subsystem_flags) {
	for (auto it = subsystem_flags.begin(); it != subsystem_flags.end(); it++) {
		initializeSystem(*it);
	}
}
Пример #3
0
 //! Requires: il.size() == Rank.
 //! Effects: For all i in the range [0, Rank), initializes the ith
 //! component of *this with *(il.begin() + i).
 index(std::initializer_list<value_type> const& il)
 {
     HPX_ASSERT(il.size() == std::size_t(rank) &&
         "il.size() must be equal to Rank");
     std::copy(il.begin(), il.end(), vs_ + 0);
 }
Пример #4
0
			vec3(std::initializer_list<float> ilist) { auto* p = ilist.begin();  x = *p++; y = *p++; z = *p++; }
Пример #5
0
 bool in(const std::initializer_list<T1>& s, const T2& x) {
     return std::find(s.begin(), s.end(), x) != s.end();
 }
Пример #6
0
 binary(std::initializer_list<uint8_t> bytes, const Alloc& alloc = Alloc())
     : binary(reinterpret_cast<const char*>(bytes.begin()), bytes.size(), alloc) {}
Пример #7
0
 void init(const std::initializer_list<int>& il) {
   vect.resize(il.size());
   std::move_backward(il.begin(), il.end(), vect.end());
 }
Пример #8
0
void KeyMultiValueTagFilter::setValues(std::initializer_list<std::string> l)
{
	setValues(l.begin(), l.end());
}
Пример #9
0
//MultiKeyTagFilter
MultiKeyTagFilter::MultiKeyTagFilter(std::initializer_list< std::string > l) :
m_KeySet(l.begin(), l.end())
{}
Пример #10
0
 pointer_vector(std::initializer_list<T> list) : pool(0), poolsize(0), objectsize(0) {
   for(const T *p = list.begin(); p != list.end(); ++p) append(*p);
 }
Пример #11
0
	/*! \brief Constructor from a list of numbers
	 *
	 * \param c list of numbers
	 *
	 */
	comb(std::initializer_list<char> c)
	{
		size_t i = 0;
	    for(char x : c)
	    {this->c[c.size() - i - 1] = x;i++;}
	}
Пример #12
0
LinkedList<T>::LinkedList(std::initializer_list<T> elements)
{
	head->data = elements.begin()[0];
}
Пример #13
0
 infer_handle_from_class_t<T>
 spawn_in_groups(std::initializer_list<group> gs, Ts&&... xs) {
   actor_config cfg;
   return spawn_class_in_groups<T, Os>(cfg, gs.begin(), gs.end(),
                                       std::forward<Ts>(xs)...);
 }
Пример #14
0
 infer_handle_from_fun_t<F>
 spawn_in_groups(std::initializer_list<group> gs, F fun, Ts&&... xs) {
   actor_config cfg;
   return spawn_fun_in_groups<Os>(cfg, gs.begin(), gs.end(), fun,
                                  std::forward<Ts>(xs)...);
 }
Пример #15
0
namespace type_traits
{
  namespace detail
  {
    template <class T> struct decay_preserving_cv
    {
      typedef typename std::remove_reference<T>::type U;
      typedef typename std::conditional<std::is_array<U>::value, typename std::remove_extent<U>::type *, typename std::conditional<std::is_function<U>::value, typename std::add_pointer<U>::type, U>::type>::type type;
    };
    // Support for SFINAE detection of iterator/pointer ranges (Can it dereference? Can it increment?)
    //    template<class T, typename = void> struct is_rangeable : std::false_type { };
    //    template<class T> struct is_rangeable<T, decltype(*std::declval<T&>(), ++std::declval<T&>(), void())> : std::true_type { };
    // Support for SFINAE detection of containers (does it have begin() and end()?), made considerably more complex by needing MSVC to work.
    template <class T> inline auto is_sequence_impl(T &&) -> decltype(*std::begin(std::declval<T>()), *std::end(std::declval<T>()), bool()) { return true; }
    inline int is_sequence_impl(...) { return 0; }

    template <class T> struct make_sequence_type
    {
      auto operator()() const -> decltype(std::declval<T>());
    };
    template <> struct make_sequence_type<void>
    {
      int operator()() const;
    };
  }
  //! True if type T is a STL compliant sequence (does it have begin() and end()?)
  template <class T, typename = decltype(detail::is_sequence_impl(detail::make_sequence_type<T>()()))> struct is_sequence : std::false_type
  {
  };
  template <> struct is_sequence<void> : std::false_type
  {
  };
  template <class T> struct is_sequence<T, bool> : std::true_type
  {
    typedef decltype(*std::begin(*((typename std::remove_reference<T>::type *) nullptr))) raw_type;  //!< The raw type (probably a (const) lvalue ref) returned by *it
    typedef typename detail::decay_preserving_cv<raw_type>::type type;                               //!< The type held by the container, still potentially const if container does not permit write access
  };


#if 0
    // Disabled until I find the time to get it working
    namespace detail
    {
      template <size_t N> struct Char
      {
        char foo[N];
      };
      // Overload only available if a default constructed T has a constexpr-available size()
      template <class T, size_t N = static_cast<T *>(nullptr)->size() + 1> constexpr inline Char<N> constexpr_size(const T &) { return Char<N>(); }
      template <class T> constexpr inline Char<1> constexpr_size(...) { return Char<1>(); }
    }
    /*! Returns true if the instance of v has a constexpr size()
    /note This is too overly conservative, it does not correctly return true for constexpr input.
    */
    template <class T> constexpr inline bool has_constexpr_size(const T &v) { return sizeof(detail::constexpr_size<typename std::decay<T>::type>(std::move(v))) > 1; }
    //! \overload
    template <class T> constexpr inline bool has_constexpr_size() { return sizeof(detail::constexpr_size<typename std::decay<T>::type>(std::declval<T>())) > 1; }

    static_assert(has_constexpr_size<std::array<std::string, 2>>(), "failed");

#if 0
      // Non-constexpr array (always has a constexpr size())
      auto ca = std::array<int, 2>();
      // Constexpr initializer_list (has constexpr size()). Note fails to compile on
      // VS2015 as its initializer_list isn't constexpr constructible yet
#ifndef _MSC_VER
      constexpr std::initializer_list<int> cil{ 1, 2 };
#endif
      // Non-constexpr initializer_list (does not have constexpr size())
      std::initializer_list<int> il{ 1, 2 };
      // Non-constexpr vector (never has constexpr size())
      std::vector<int> vec{ 1, 2 };

      // Correct on GCC 4.9 and clang 3.8 and VS2015
      static_assert(ca.size(), "non-constexpr array size constexpr");
      // Correct on GCC 4.9 and clang 3.8.
#ifndef _MSC_VER
      static_assert(cil.size(), "constexpr il size constexpr");
#endif
      // Fails as you'd expect everywhere with non-constexpr il error
      // static_assert(il.size(), "non-constexpr il size constexpr");

      // Correct on GCC 4.9 and clang 3.8 and VS2015
      static_assert(has_constexpr_size(ca), "ca");
      // Incorrect on GCC 4.9 and clang 3.8 and VS2015
#ifndef _MSC_VER
      static_assert(!has_constexpr_size(cil), "cil");  // INCORRECT!
#endif
                                                       // Correct on GCC 4.9 and clang 3.8 and VS2015
      static_assert(!has_constexpr_size(il), "il");
      // Correct on GCC 4.9 and clang 3.8 and VS2015
      static_assert(!has_constexpr_size(vec), "vec");

      constexpr bool test_ca() {
        return has_constexpr_size(std::array<int, 2>{1, 2});
      }
      constexpr bool testca = test_ca();
      // Correct on GCC 4.9 and clang 3.8 and VS2015
      static_assert(testca, "testca()");

      constexpr bool test_cil() {
        return has_constexpr_size(std::initializer_list<int>{1, 2});
      }
      constexpr bool testcil = test_cil();
      // Incorrect on GCC 4.9 and clang 3.8 and VS2015
      static_assert(!testcil, "testcil()");          // INCORRECT!
#endif
#endif
}
Пример #16
0
void MultiKeyTagFilter::addValues(std::initializer_list<std::string> l)
{
	addValues(l.begin(), l.end());
}
Пример #17
0
VertexDescription::VertexDescription(std::initializer_list<VertexDescriptionElement> elements) {
  m_elements.resize(elements.size());
  std::copy(elements.begin(), elements.end(), m_elements.begin());
}
Пример #18
0
Value Object::callAsFunction(std::initializer_list<JSValueRef> args) const {
  return callAsFunction(nullptr, args.size(), args.begin());
}
Пример #19
0
 /// constructor using initializer list
 VectorBase(std::initializer_list<value_type> l) 
   : super(l.size())
 {
   std::copy(l.begin(), l.end(), _elements);
 }
Пример #20
0
Value Object::callAsFunction(const Object& thisObj, std::initializer_list<JSValueRef> args) const {
  return callAsFunction((JSObjectRef)thisObj, args.size(), args.begin());
}
Пример #21
0
					local(std::initializer_list<int> ilist)
					{
						payload1 = ilist.begin()[0];
						payload2 = ilist.begin()[1];
					}
Пример #22
0
node::node( op_id o, const dimensions &d, std::initializer_list<node_id> inputs, any val, hash::value hv )
	: _hash( std::move( hv ) ), _dims( d ), _value( std::move( val ) ), _op_id( o )
{
	resize_edges( static_cast<uint32_t>( inputs.size() ), 0 );
	std::copy( inputs.begin(), inputs.end(), _edges );
}
Пример #23
0
 strict_lock(std::initializer_list<thread_detail::lockable_wrapper<Lockable> > l_) :
   mtx_(*(const_cast<thread_detail::lockable_wrapper<Lockable>*>(l_.begin())->m))
 {
   mtx_.lock();
 }
Пример #24
0
	Response BaseDiscordClient::request(const RequestMethod method, Route path, const std::string jsonParameters/*,
		cpr::Parameters httpParameters*/, const std::initializer_list<Part>& multipartParameters) {
		//check if rate limited
		Response response;
		const time_t currentTime = getEpochTimeMillisecond();
		if (isGlobalRateLimited) {
			if (nextRetry <= currentTime) {
				isGlobalRateLimited = false;
			} else {
				onExceededRateLimit(isGlobalRateLimited, nextRetry - currentTime, { *this, method, path, jsonParameters, multipartParameters });
				response.statusCode = TOO_MANY_REQUESTS;
				setError(response.statusCode);
				return response;
			}
		}
		const std::string bucket = path.bucket(method);
		auto bucketResetTimestamp = buckets.find(bucket);
		if (bucketResetTimestamp != buckets.end()) {
			if (bucketResetTimestamp->second <= currentTime) {
				buckets.erase(bucketResetTimestamp);
			} else {
				onExceededRateLimit(false, bucketResetTimestamp->second - currentTime, { *this, method, path, jsonParameters, multipartParameters });
				response.statusCode = TOO_MANY_REQUESTS;
				setError(response.statusCode);
				return response;
			}
		}
		{	//the { is used so that onResponse is called after session is removed to make debugging performance issues easier
			//request starts here
			Session session;
			session.setUrl("https://discordapp.com/api/v6/" + path.url());
			std::vector<HeaderPair> header = {
				{ "Authorization", bot ? "Bot " + getToken() : getToken() },
				{ "User-Agent", "DiscordBot (https://github.com/yourWaifu/SleepyDiscord, vtheBestVersion)" },
			};
			if (jsonParameters != "") {
				session.setBody(&jsonParameters);
				header.push_back({ "Content-Type"  , "application/json"                      });
				header.push_back({ "Content-Length", std::to_string(jsonParameters.length()) });
			//} else if (httpParameters.content != "") {	//this is broken for now
			//	session.SetParameters(httpParameters);
			} else if (0 < multipartParameters.size()) {
				session.setMultipart(multipartParameters);
				header.push_back({ "Content-Type", "multipart/form-data" });
			} else {
				header.push_back({ "Content-Length", "0" });
			}
			session.setHeader(header);
			//Response response;
			switch (method) {
			case Post:   response = session.Post();   break;
			case Patch:  response = session.Patch();  break;
			case Delete: response = session.Delete(); break;
			case Get:    response = session.Get();    break;
			case Put:    response = session.Put();    break;
			default:     response.statusCode = BAD_REQUEST; break; //unexpected method
			}
			//status checking
			switch (response.statusCode) {
			case OK: case CREATED: case NO_CONTENT: case NOT_MODIFIED: break;
			case TOO_MANY_REQUESTS: {   //this should fall down to default
				int retryAfter = std::stoi(response.header["Retry-After"]);
				isGlobalRateLimited = response.header["X-RateLimit-Global"] == "true";
				nextRetry = getEpochTimeMillisecond() + retryAfter;
				if (!isGlobalRateLimited)
					buckets[bucket] = nextRetry;
				onExceededRateLimit(isGlobalRateLimited, retryAfter, { *this, method, path, jsonParameters, multipartParameters });
			}
			default:
			{		//error
				const ErrorCode code = static_cast<ErrorCode>(response.statusCode);
				setError(code);		//https error
				std::vector<std::string> values = json::getValues(response.text.c_str(),
				{ "code", "message" });	//parse json to get code and message
				if (!values.empty() && values[0] != "")
					onError(static_cast<ErrorCode>(std::stoi(values[0])), values[1]);	//send message to the error event
				else
					onError(ERROR_NOTE, response.text);
#if defined(__cpp_exceptions) || defined(__EXCEPTIONS)
				throw code;
#endif
			} break;
			}
			//rate limit check
			if (response.header["X-RateLimit-Remaining"] == "0" && response.statusCode != TOO_MANY_REQUESTS) {
				std::tm date = {};
				//for some reason std::get_time requires gcc 5
				std::istringstream dateStream(response.header["Date"]);
				dateStream >> std::get_time(&date, "%a, %d %b %Y %H:%M:%S GMT");
				const time_t reset = std::stoi(response.header["X-RateLimit-Reset"]);
#if defined(_WIN32) || defined(_WIN64)
				std::tm gmTM;
				std::tm*const resetGM = &gmTM;
				gmtime_s(resetGM, &reset);
#else
				std::tm* resetGM = std::gmtime(&reset);
#endif
				const time_t resetDelta = (std::mktime(resetGM) - std::mktime(&date)) * 1000;
				buckets[bucket] = resetDelta + getEpochTimeMillisecond();
				onDepletedRequestSupply(resetDelta, { *this, method, path, jsonParameters, multipartParameters });
			}
		}
 constexpr Z(std::initializer_list<int> il) : i_(il.begin()[0]), j_(il.begin()[1])
     {throw 6;}
Пример #26
0
Map(std::initializer_list<std::pair<const Key, Value> > list){
  for(auto i = begin(list); list.end(list); ++i){
    bst->insert(*i);
  }
}
Пример #27
0
void test_container( std::initializer_list<T>& c )
{
    assert ( std::size(c)   == c.size());
}
Пример #28
0
extern bool check_args(RuntimeInfo& runinfo, 
	const std::vector<Symbol*>& vecSyms, 
	const std::initializer_list<unsigned int>& lstTypes, 
	const std::initializer_list<bool> &lstOptional, 
	const char* pcFkt, const char* pcErr)
{
	const std::size_t iSyms = vecSyms.size();
	const std::size_t iTypes = lstTypes.size();
	const std::size_t iTotalOpt = lstOptional.size();
	std::size_t iCompulsory = 0;
	for(bool bOpt : lstOptional)
		if(!bOpt) ++iCompulsory;

	if(iSyms < iCompulsory)
	{
		std::ostringstream ostrErr;
		ostrErr << linenr(runinfo)
			<< "Function \"" << pcFkt << "\""
			<< " requires " << iCompulsory
			<< " arguments, but only "
			<< iSyms << " were given.";
		if(pcErr) ostrErr << " " << pcErr;
		ostrErr << std::endl;
		throw tl::Err(ostrErr.str(),0);
	}


	std::vector<Symbol*>::const_iterator iterSym = vecSyms.begin();
	std::initializer_list<unsigned int>::iterator iterTypes = lstTypes.begin();
	std::initializer_list<bool>::iterator iterOptional = lstOptional.begin();

	std::size_t iCurSym = 0;
	for(; iterSym!=vecSyms.end(); ++iterSym, ++iterTypes, ++iterOptional, ++iCurSym)
	{
		// ignore remaining symbols
		if(iCurSym >= iTypes || iCurSym >= iTotalOpt)
			break;

		if(!*iterSym)
		{
			std::ostringstream ostrErr;
			ostrErr << linenr(runinfo)
				<< "Argument " << (iCurSym+1)
				<< " of function \"" << pcFkt << "\""
				<< " is invalid.";
			if(pcErr) ostrErr << " " << pcErr;
			ostrErr << std::endl;

			throw tl::Err(ostrErr.str(),0);
		}

		if(!(*iterTypes & (*iterSym)->GetType()))
		{
			std::ostringstream ostrErr;
			ostrErr << linenr(runinfo)
				<< "Argument " << (iCurSym+1)
				<< " of function \"" << pcFkt << "\""
				<< " has wrong type. "
				<< "Expected " << get_type_name(*iterTypes)
				<< ", received " << get_type_name((*iterSym)->GetType()) 
				<< ".";
			if(pcErr) ostrErr << " " << pcErr;
			ostrErr << std::endl;

			throw tl::Err(ostrErr.str(),0);
		}
	}

	return 1;
}
Пример #29
0
 HALMD_GPU_ENABLED fixed_vector(std::initializer_list<U> const& v,
   typename std::enable_if<std::is_convertible<U, double>::value>::type* dummy = 0)
 {
     assert( v.size() == _Base::size() );
     std::copy(v.begin(), v.end(), _Base::begin());
 }
Пример #30
0
void test_container( std::initializer_list<T>& c)
{
    assert ( std::data(c)   == c.begin());
}