小编yua*_*uan的帖子

如何查找几分钟前访问/创建的文件

我总是忘记我在一分钟前编辑的文件,所以我输入find . -cmin 1或者其他一些值,但它只运行了1几分钟.我不得不试试find . -ctime 2 /*or 3,4...*/.

然后我找到了另一种更好的方法:

touch -t 12251134 empty /*similar format which 5 or 10 minutes ago */
find . -newer empty
Run Code Online (Sandbox Code Playgroud)

我可以用我date -d'-5minutes' +%m%d%H%M计算时间.我想知道是否有一种简单的方法来查找1,2或3分钟前访问过的文件.

unix linux bash shell find

65
推荐指数
3
解决办法
10万
查看次数

什么是模板推导中的部分排序程序

阅读C++ 11标准我无法完全理解以下语句的含义.例子非常受欢迎.

两组类型用于确定部分排序.对于涉及的每个模板,都有原始函数类型和转换后的函数类型.[注意:转换类型的创建在14.5.6.2中描述. - 结束注释]演绎过程使用变换后的类型作为参数模板,将另一个模板的原始类型用作参数模板.对于部分排序比较中涉及的每种类型,此过程完成两次:一次使用转换的模板-1作为参数模板,使用template-2作为参数模板,再次使用转换的模板-2作为参数模板和模板-1作为参数模板
- N3242 14.8.2.4.2

c++ templates partial-ordering c++11 template-argument-deduction

34
推荐指数
1
解决办法
3210
查看次数

为什么我的T&和T &&复制构造函数模糊不清?

#include <iostream>
using namespace std;
class Myclass{
        private:
                int i;
        public:
                template<typename U>Myclass(U& lvalue):i(lvalue){cout<<i <<" template light reference" <<endl;i++;}
                //Myclass(Myclass &lvalue):i(lvalue){cout<<i <<" light reference" <<endl;i++;}
                template<typename U>Myclass(U&& rvalue):i(rvalue){cout<<i <<" template right reference" <<endl;i++;}
};

int main(int argc,char*argv[])
{
Myclass a(0);
Myclass b(a);
Myclass c(2);
return 0;
}
Run Code Online (Sandbox Code Playgroud)

错误信息:

rightvalue.cpp: In function ‘int main(int, char**)’:
rightvalue.cpp:15:12: error: call of overloaded ‘Myclass(Myclass&)’ is ambiguous
rightvalue.cpp:15:12: note: candidates are:
rightvalue.cpp:10:23: note: Myclass::Myclass(U&&) [with U = Myclass&]
rightvalue.cpp:8:23: note: Myclass::Myclass(U&) [with U = Myclass] …
Run Code Online (Sandbox Code Playgroud)

c++ templates c++11

8
推荐指数
1
解决办法
1181
查看次数

为什么javascript在删除时区分有或没有声明的赋值?

在全局上下文中执行以下代码:

var x = 1;
y = 1
delete x //false
delete y //true
Run Code Online (Sandbox Code Playgroud)

这两个xy是全局对象的属性.为什么javascript必须在某种程度上区分它们?


这很容易按套路accoring到ES5标准delete运营商对象的内部方法[[delete]].

更明确的问题是他们为什么采用不同的[[configurable]]属性?

javascript

6
推荐指数
1
解决办法
109
查看次数

模板演绎似乎有误

推导出的模板似乎是错误的,为什么(c)被调用而不是(b)?

#include <iostream>
using namespace std;
template<class T> void f(T){cout << "f(T)";}//(a)
template<> void f<>(int*){cout << "f(int*)";}//(b)
template<class T> void f(T*){cout << "f(T*)";}//(c)
//void f(int*){cout <<"POD:f(int*)";}//(d)

int main(int argc,char*argv[])
{
    int p = 1;
    f(&p);
    cout <<endl;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

输出:

f(T*)

c++ templates

5
推荐指数
1
解决办法
117
查看次数

使用/ dev/random文件io需要太长时间

我想写一个程序来使用/dev/randomlinux 生成真正随机的数字,但后来我发现它的运行时间偶尔是不可接受的.它的C版本运行速度一致.

#include <iostream>
#include <fstream>
using namespace std;
int main(int argc,char*argv[])
{
    ifstream random("/dev/random", ios_base::in);
    int t;
    random.read(reinterpret_cast<char*>(&t), sizeof(t));
    cout << t << endl;
    random.close();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

运行时间的时间统计

$: time ./random 
-1040810404

real    0m0.004s
user    0m0.000s
sys 0m0.000s

$: time ./random 
-1298913761

real    0m4.119s
user    0m0.000s
sys 0m0.000s
Run Code Online (Sandbox Code Playgroud)

c++

5
推荐指数
1
解决办法
782
查看次数

可以通过int初始化vector &lt;bool&gt;

我想枚举bool表示形式[0,31]并将其存储以tries供以后使用。

static const int N = 5;
vector<bool> tries(N);

for(int i = 0;i < (2<<N); i++){

    //can vector<bool> initialized by int?
    //so I don't have to do bit operation

    for (int t = 0; t < N; ++t)
    {
        tries[t] = i&(1UL<<t);
    }

...
}
Run Code Online (Sandbox Code Playgroud)

c++

4
推荐指数
1
解决办法
767
查看次数

libstdc ++有什么功能.所以提供?

几乎所有真正的可执行c ++程序都链接到libstdc ++.所以.这个共享库提供什么样的功能?

我认为很多工作都是在编译时完成的,例如模板实例化,这在编译之前是无法完成的.

c++

3
推荐指数
2
解决办法
2831
查看次数

如何以及何时使用构造函数模板?

我对下面的句子感到困惑,我理解它们用于转换成员函数的示例,但不理解构造函数成员函数模板的场合,Mankarse给出了有益的示例

因为显式模板参数列表紧随功能模板名称,并且由于在不使用函数名称的情况下调用转换成员函数模板和构造函数成员函数模板,所以无法为这些功能模板提供显式模板参数列表。 --14.5.2.5 N3242

struct A {
    template <class T> operator T*();
};
template <class T> A::operator T*(){ return 0; }
template <> A::operator char*(){ return 0; } // specialization
template A::operator void*(); // explicit instantiation

int main() 
{
   A a;
   int *ip;
   ip = a.operator int*(); // explicit call to template operator
   // A::operator int*()
}
Run Code Online (Sandbox Code Playgroud)

类模板的成员函数的模板参数由调用成员函数的对象类型的模板参数确定。--14.5.1.1.2 N3242

因此,我需要自己扣除模板参数或使用包装器。
读取标准库时libstdc ++给出的示例:

template<typename _Container>
class back_insert_iterator
: public iterator<output_iterator_tag, void, void, void, void>
{
   protected:
      _Container* container; …
Run Code Online (Sandbox Code Playgroud)

c++

2
推荐指数
1
解决办法
1251
查看次数

argv [0]如何运作

我知道这argv[0]代表了可执行文件名,但我不明白它是如何实现的 - 它如何在源代码级别获取文件名和选项.起初我以为它依赖于linux中的内置函数,但后来发现windows也支持它,让我相信它可能是由编译器完成的?

c command-line-arguments

1
推荐指数
1
解决办法
1329
查看次数

当初始化列表中没有更多元素时,是否初始化了数组的rest元素

这种行为是否定义明确?

#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
    int a[10] = {1, 2, 3, 4, 5};
    for(const auto &i: a)
        cout << i << endl;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

输出:

1
2
3
4
5
0
0
0
0
0
Run Code Online (Sandbox Code Playgroud)

c++ c++11

1
推荐指数
1
解决办法
193
查看次数

宏输出不起作用

我正在学习c ++,宏观行为并不像预期的那样.

  1     #include<cstdlib>
  2     #include<iostream>
  3     #include<cstring>
  4     #define die(x) std::cout << x << std::endl ; exit(-1) 
  5     const char *help = "Usage: coffee --help --version";
  6     const char *version = "alpha";
  7     int main(int argc,char **argv)
  8     {
  9               if(argc<2||!strcmp(argv[1],"--help"))
 10                       die(help);
 11               if(!strcmp(argv[1],"--version"))
 12                       die(version);
 13 
 14               return 0;
 15               
 16     }
Run Code Online (Sandbox Code Playgroud)
g++ -o sample ./*
./sample --help
Run Code Online (Sandbox Code Playgroud)

输出:用法:coffee --help --version

./sample --version  
Run Code Online (Sandbox Code Playgroud)

输出:


I'm confused why --version没有输出字符串alpha.

c++

0
推荐指数
1
解决办法
141
查看次数

为什么转换不能完成隐含

由于没有进行转换,第14行中的代码无法编译,但由于显式转换运算符,16,17中的代码工作正常.

  1 
  2 #include <iostream>
  3 using namespace std;
  4 template<typename T,int N>class Array{
  5         private:
  6         T _M_data[N];
  7         public:
----        operator T*(){return _M_data;}
----        operator T(){return _M_data[0];}
++++        T* data(){return _M_data;}
 10 };
 11 int main(int argc,char*argv[])
 12 {
 13         Array<int,5> i5A ;
 14         //printf("%d\n",i5A);   
 15         //won't work,need explicit conversion 
 16         printf("%d\n",i5A.operator int()); 
 17         printf("%p\n",i5A.operator int*());
 18 return 0;
 19 }
Run Code Online (Sandbox Code Playgroud)

更新:
我知道为什么标准需要一个data()功能:printf("%d\n",*(i5A.data()));

c++

0
推荐指数
1
解决办法
81
查看次数