#include <iostream>
constexpr int countArgs() { return 0; }
template <class Arg, class ... Args>
constexpr int countArgs(const Arg& x, const Args& ... args)
{
return countArgs(args...) + 1;
}
int main()
{
std::cout << countArgs() << std::endl;
std::cout << countArgs(1, 2, 3) << std::endl;
return 0;
}
#include <iostream>
#include <cstdarg>
constexpr int countArgs() { return 0; }
template <class ... Args>
constexpr int countArgs(int x, Args ... args)
{
return countArgs(args...) + 1;
}
void outArgsInner(int count, ...)
{
va_list ap;
va_start(ap, count);
if (count > 0) {
std::cout << va_arg(ap, int);
for (int i = 2; i <= count; ++i) {
std::cout << ' ' << va_arg(ap, int);
}
}
va_end(ap);
std::cout << std::endl;
}
template <class ... Args>
inline void outArgs(Args ... args)
{
outArgsInner(countArgs(args...), args...);
}
int main()
{
outArgs(); // пустой тоже работает
outArgs(1, 2, 3);
// outArgs("a", 2, 3); тут ошибка! — и верно, мы принимаем только int’ы
return 0;
}
template <class T>
class ChunkMap
{
public:
// Data access
//------------------------------------------------------------------------//
/// @return data at index t, or empty value
T get(size_t t) const;
//------------------------------------------------------------------------//
/// Sets data at index t (empty value to erase)
void put(size_t t, T x);
//------------------------------------------------------------------------//
/// Erases range [0..maxPlus)
void eraseTo(size_t aMaxPlus);
// Info
size_t nChunks() const { return fChunks.size(); }
bool isEmpty() const { return fChunks.empty(); }
//------------------------------------------------------------------------//
/// @return the number that is beyond all chunks
size_t ceil() const;
//------------------------------------------------------------------------//
/// @return actual number of records in the map
size_t size() const;
//------------------------------------------------------------------------//
/// @return lowest value in the map; (0, empty) if empty
std::pair<size_t, T> lowerValue() const;
//------------------------------------------------------------------------//
/// @return highest value in the map; (0, empty) if empty
std::pair<size_t, T> upperValue() const;
//------------------------------------------------------------------------//
/// @return (t1, v), t1 <= t; (0, empty) if none
std::pair<size_t, T> lowerOrEq(size_t t) const;
template <class Body> void loop(const Body& r) const;
template <class Body> void loopFrom(size_t aMin, const Body& r) const;
//------------------------------------------------------------------------//
/// Loops all data. Body is bool-convertible.
/// Return true → go on.
/// Return false → stop and return false.
template <class Body> bool loopBool(const Body& r) const;
void clear() { fChunks.clear(); }
constexpr static T emptyValue() { return std::numeric_limits<T>::max(); }
static bool isEmptyValue(const T& x) { return (x == emptyValue()); }
constexpr static unsigned chunkSize() { return Chunk::SIZE; }
private:
struct Chunk
{
enum { SIZE = 8 };
Fix1d<T, SIZE> data; // мой шаблон, массив фиксированного размера с проверкой на выход за границы
Chunk();
bool isEmpty() const;
std::pair<size_t, T> lowerValue(size_t aKey) const;
std::pair<size_t, T> upperValue(size_t aKey) const;
};
typedef std::map<size_t, Chunk> Chunks;
Chunks fChunks;
};
ui
. Когда вы делаете форму программно, им не обязательно там быть, но редактор форм делает именно так.if (ui->textEdit->text() == "Hi") label->setText("Hi!");
extern template class
).// В схеме «одна единица компиляции»: ничего не делать.
// В схеме «много единиц компиляции»: лишняя зависимость; унести в unit1.cpp
#include <cstdlib>
// В схеме «одна единица компиляции»: убрать extern.
// В схеме «много единиц компиляции»: завести unit1.cpp, там сделать MyType x;
extern MyType X;
// В схеме «одна единица компиляции»: ничего не делать.
// В схеме «много единиц компиляции»: перенести функцию в unit1.cpp, оставив в .h только прототип.
void XReset() {}
srand(time(NULL));
. Я не знаю, что в функции random_at_most, но если там srand — перенеси его в другое место. Процессор работает в миллион раз быстрее, чем таймер. «Хочешь, чтобы было случайнее», а будут повторы. sz = strlen(szPath);
Return value
If the function succeeds, the return value is the length of the string that is copied to the buffer, in characters, not including the terminating null character. If the buffer is too small to hold the module name, the string is truncated to nSize characters including the terminating null character, the function returns nSize, and the function sets the last error to ERROR_INSUFFICIENT_BUFFER.
void Wid::test() {
vector<string> stp;
stp.push_back(text->toPlainText().toStdString());
// В stp одна штука
sort(stp.begin(),stp.end());
// Ну что ей будет, этой штуке?
stp.erase(unique(stp.begin(),stp.end()),stp.end());
// unique даст end; поведение vector при этом не определено.
ofstream filesave(pp);
copy(stp.begin(),stp.end(), ostream_iterator<string>(filesave,"\n"));
}
word1 = word;
word1[0] = 'X';
word1 = QString::fromUtf8(ar.data());
word1[0] = 'X';