#include<iostream>
#include <vector>
#include <initializer_list>
#include <string>
#include<cstdarg>
using namespace std;
typedef int arrT[10];
using arrT = int[10];
arrT* funlc(int i);
int fact(int val)
{
int ret = 1;
while (val>1)
ret *= val--;
return ret;
}
size_t count_calls()
{
static size_t ctr = 0;
return ++ctr;
}
void print(vector<int >::const_iterator beg,
vector<int>::const_iterator end);
void reset(int &i)
{
i = 0;
}
bool isShorter(const string&s1, const string &s2)
{
return s1.size() > s2.size();
}
string::size_type find_char(const string &s, char c, string::size_type &occurs)
{
auto ret = s.size();
occurs = 0;
for (decltype(ret) i = 0; i != s.size(); ++i)
{
if (s[i] == c)
{
if (ret == s.size())
ret = i;
++occurs;
}
}
return ret;
}
void func(const int i)
{
}
void funcc(int i )
{
}
int i = 42;
const int *cp = &i;
const int &r = i;
const int &r2 = 42;
bool is_sentence(const string&s)
{
string::size_type ctr = 0;
return find_char(s, '.', ctr) == s.size() - 1 && ctr == 1;
}
bool is_enpty(string&s)
{
return s.empty();
}
void print(const char *cp)
{ while (*cp)
cout << *cp++;
}
void print(const int *beg, const int *end)
{
while (beg!= end)
cout << *beg++ << endl;
}
void print(const int ia[], size_t size)
{
for (size_t i = 0; i != size;i++)
{
cout << ia[i] << endl;
}
}
void print(int (&arr)[10])
{
for (auto elem:arr)
{
cout << elem << endl;
}
}
void print(int (*matrix)[10],int Rowsize);
initializer_list<int>lii;
initializer_list<string>ls;
void error_msg(initializer_list<string> li)
{
for (auto beg = li.begin(); beg != li.end();++beg)
{
cout<<*beg<<endl;
}
}
void foo(...);
void foo(int ,int, ...);
void swap(int &v1, int&v2)
{
if (v1 == v2)
return;
int tmp = v2;
v2 = v1;
v1 = tmp;
}
bool str_subrange(const string &s1, const string &s2)
{
if (s1.size() == s2.size())
return s1 == s2;
auto size = (s1.size() < s2.size() ? s1.size() : s2.size());
for (decltype(size) i = 0; i != size; ++i)
{
if (s1[i] != s2[i])
return true;
}
return true;
}
string make_plural(size_t ctr,const string &word,const string&ending)
{
return (ctr > 1) ? word + ending : word;
}
vector<string>process(string expected,string actual)
{
if (expected.empty())
{
return{};
}
else if (expected == actual)
return{ "functionX", "OKEY" };
else
return{ "Function", expected, actual };
}
int factorial(int val)
{
if (val > 1)
return factorial(val - 1)*val;
return 1;
}
int print(vector<int >&li,int i=0)
{
if (i==li.size())
return 0;
cout << li[i++] <<" ";
print(li, i);
}
auto function(int i)->int(*)[10];
int odd[] = { 1, 3, 5, 7, 9 };
int even[] = { 2, 5, 346, 7, 3};
decltype(odd)*arrptr(int i)
{
return (i % 2) ? &odd : &even;
}
const string &shorterString(const string &s1, const string &s2)
{
cout << "调用 const string &" << endl;
return s1.size() <= s2.size() ? s1 : s2;
}
string &shorterString(string &s1, string &s2)
{
cout << "调用 string &2" << endl;
auto &r = shorterString((const_cast<const string&>(s1)), (const_cast<const string &>(s2)));
return const_cast<string &>(r);
}
typedef string::size_type sz;
string screen(sz ht = 24, sz wid = 80, char background = ' ');
string screen(sz ht,sz wid, char background );
void printl(const int ia[], size_t size)
{
#ifndef NDEBUG
cerr << __FUNCTION__ << "array size is" << size << endl;
#endif
}
bool lengthCompare(const string &, const string &);
bool(*pf)(const string &, const string &);
bool *plf(const string &, const string &);
void ff(int *);
void ff(unsigned int);
void(*pf1)(unsigned int) = ff;
void useBigger(const string &s1, const string &s2, bool pf(const string&, const string &));
typedef decltype(lengthCompare) Func2;
typedef bool func1(const string&, const string &);
typedef decltype(lengthCompare) *Funcp2;
typedef bool *funcp1(const string&, const string &);
int main(int argc,char **argv)
{
string window;
const string s1 = "hello";
const string s2 = "world";
string s3, s4;
shorterString(s1, s2);
shorterString(s3, s4);
vector<int>ceshi = { 1, 2, 3, 4, 5, 6, 6, 7, 5};
print(ceshi);
string s = "afadgsd";
string ls1 = "asfdfgxbfghe";
process(s,ls1);
int j[] = { 2, 1, 3 };
printl(j, 3);
print(begin(j), end(j));
print(j, end(j) - begin(j));
system("pause");
}