1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
// include guard
#ifndef CPP_EXTRA_H_INCLUDED
#define CPP_EXTRA_H_INCLUDED
#include <iostream>
// <chrono> and <thread> are standard C++ headers
#include <chrono>
#include <thread>
/*
Credits:
Devolper: Toggy11
*/
/*
Info:
Please do NOT say this code is yours.
If you want to make changes to it that
is fine. You MUST ask me if you want
to make a download for ANY version
of C++Extra, wether it be your
version or the one supplied by
download.
*/
inline void clear() // inline function with external linkage
// can be defined (identically) in multiple translation units
{
static const int PAGE_SIZE = 50 ; // number of lines per page
for( int i = 0 ; i < PAGE_SIZE ; ++i ) // print PAGE_SIZE empty lines
std::cout << '\n' ;
}
static void load() // static => internal linkage
// eaxh translation unit has its own definition
{
// 600 milliseconds
static const auto delay = std::chrono::milliseconds(600) ;
std::cout << "Loading. . .\n" ;
// this requires a conforming C++ compiler
// for every integer 'percent' in the brace-enclosed-list
for( int percent : { 1, 5, 11, 23, 26, 37, 41, 43, 47, 56, 67,
72, 75, 83, 91, 94, 98, 100 } )
{
std::cout << percent << '%' << std::endl ; // force an immediate line of output
// before we go into a wait state
// sleep for the duration specified
// http://en.cppreference.com/w/cpp/thread/sleep_for
std::this_thread::sleep_for( delay ) ;
}
std::cout << "Done loading!\n" ;
}
#endif // CPP_EXTRA_H_INCLUDED
|