source: trunk/m4/yat_cxx11.m4 @ 3590

Last change on this file since 3590 was 3590, checked in by Peter, 6 years ago

change file name to more generic 'yat_cxx11.m4' (laying out the carpet for more macros)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Date
File size: 2.6 KB
Line 
1## $Id: yat_cxx11.m4 3590 2017-01-20 00:23:07Z peter $
2#
3# serial 2  (yat 0.15)
4#
5# see http://www.gnu.org/software/automake/manual/automake.html#Serials
6#
7# SYNOPSIS
8#
9#   YAT_CXX_RVALUE([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
10#
11# DESCRIPTION
12#
13#   Test whether $CXX supports rvalues
14#
15# LAST MODIFICATION
16#
17#   $Date: 2017-01-20 00:23:07 +0000 (Fri, 20 Jan 2017) $
18#
19# COPYLEFT
20#
21#   Copyright (C) 2017 Peter Johansson
22#
23#   This file is part of the yat library, http://dev.thep.lu.se/yat
24#
25#   The yat library is free software; you can redistribute it and/or
26#   modify it under the terms of the GNU General Public License as
27#   published by the Free Software Foundation; either version 3 of the
28#   License, or (at your option) any later version.
29#
30#   The yat library is distributed in the hope that it will be useful,
31#   but WITHOUT ANY WARRANTY; without even the implied warranty of
32#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
33#   General Public License for more details.
34#
35#   You should have received a copy of the GNU General Public License
36#   along with yat. If not, see <http://www.gnu.org/licenses/>.
37#
38
39AC_DEFUN([YAT_CXX_RVALUE],
40[AC_MSG_CHECKING([for $CXX option to enable rvalue])
41AC_CACHE_VAL([yat_cv_cxx_rvalue],
42  [yat_cv_cxx_rvalue=no
43   yat_cxx_rvalue_save_CXX=$CXX
44# From autoconf 'c.m4' we have
45# GCC -std=c++11 -std=c++0x
46# IBM XL C -qlanglvl=stdcxx11
47# HP aC++ -AA
48# INTEL -std=c++11 -std=c++0x
49# from ax_cxx_compile_stdcxx.m4 we have
50# HP's aCC needs +std=c++11
51# Cray's crayCC '-h std=c++11'
52# but first we try with empty string, hoping compiler is modern.
53   for yat_arg in '' -std=c++11 -std=c++0x -qlanglvl=stdcxx11 -AA +std=c++11 "-h std=c++11" ; do
54     CXX="$yat_cxx_rvalue_save_CXX $yat_arg"
55     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([YAT_CXX_RVALUE_HEADER],
56                                        [YAT_CXX_RVALUE_BODY])],
57                       [yat_cv_cxx_rvalue="$yat_arg"],
58                       [])
59     AS_IF([test x"$yat_cv_cxx_rvalue" != x"no"], [break])
60   done
61   CXX="$yat_cxx_rvalue_save_CXX"
62  ])
63
64AS_CASE([x"$yat_cv_cxx_rvalue"],
65        [x], [AC_MSG_RESULT([none needed])],
66        [x"no"], [AC_MSG_RESULT([unsupported])],
67        [CXX="$CXX $yat_cv_cxx_rvalue"
68         AC_MSG_RESULT([$yat_cv_cxx_rvalue])])
69AS_VAR_IF([yat_cv_cxx_rvalue], [no], [$2], [$1])
70])
71
72
73AC_DEFUN([YAT_CXX_RVALUE_HEADER],
74[
75@%:@include <utility>
76
77class MyClass
78{
79public:
80  MyClass(void);
81  MyClass(const MyClass&); // copy constructor
82  MyClass(MyClass&&); // move constructor
83  MyClass& operator=(const MyClass&); // copy assignment
84  MyClass& operator=(MyClass&&); // move assignment
85};
86])
87
88
89AC_DEFUN([YAT_CXX_RVALUE_BODY],
90[
91  MyClass mc;
92  MyClass mc2 = std::move(mc);
93])
Note: See TracBrowser for help on using the repository browser.