Changeset 3591 for trunk/m4/yat_cxx11.m4


Ignore:
Timestamp:
Jan 20, 2017, 3:19:49 AM (6 years ago)
Author:
Peter
Message:

fixes #877

Generalize YAT_CXX_RVALUE into YAT_CXX_TRY_CXX11 and use that to
implement new macro YAT_CXX_ATOMIC. Use this macro in configure.ac and
use std::atomic<> conditoionally in RNG singleton.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/m4/yat_cxx11.m4

    r3590 r3591  
    77# SYNOPSIS
    88#
     9#   YAT_CXX_ATOMIC([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
    910#   YAT_CXX_RVALUE([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
    1011#
     
    3738#
    3839
     40# YAT_CXX_ATOMIC([action-if-found], [action-if-not-found])
     41#
     42# Test whether $CXX supports std::atomic. If not, try turning on
     43# support with a number of different switches. If a successful switch
     44# is found invoke shell action-if-found; else issue
     45# action-if-not-found.
     46AC_DEFUN([YAT_CXX_ATOMIC],
     47[
     48YAT_CXX_TRY_CXX11([atomic],
     49  [@%:@include <atomic>],
     50  [std::atomic<bool> ready(false);],
     51  [$1], [$2])
     52])
     53
     54
     55# YAT_CXX_RVALUE([action-if-found], [action-if-not-found])
     56#
     57# Test whether $CXX supports rvalue. If not, try turning on support
     58# with a number of different switches. If a successful switch is found
     59# invoke shell action-if-found; else issue action-if-not-found.
    3960AC_DEFUN([YAT_CXX_RVALUE],
    40 [AC_MSG_CHECKING([for $CXX option to enable rvalue])
    41 AC_CACHE_VAL([yat_cv_cxx_rvalue],
    42   [yat_cv_cxx_rvalue=no
    43    yat_cxx_rvalue_save_CXX=$CXX
     61[
     62YAT_CXX_TRY_CXX11([rvalue], [ dnl header
     63  @%:@include <utility>
     64
     65  class MyClass
     66  {
     67  public:
     68    MyClass(void);
     69    MyClass(const MyClass&); // copy constructor
     70    MyClass(MyClass&&); // move constructor
     71    MyClass& operator=(const MyClass&); // copy assignment
     72    MyClass& operator=(MyClass&&); // move assignment
     73  };
     74  ],[ dnl body
     75  MyClass mc;
     76  MyClass mc2 = std::move(mc);
     77  ], [# action
     78  $1
     79  ], [ # action if not found
     80  $2
     81  ])
     82]) # YAT_CXX_RVALUE
     83
     84# YAT_CXX_TRY_CXX11([feature], [header], [body], [action-if-found],
     85#                   [action-if-not-found])
     86#
     87AC_DEFUN([YAT_CXX_TRY_CXX11],
     88[AS_VAR_PUSHDEF([my_CACHE], [yat_cv_cxx_$1])dnl
     89AC_CACHE_CHECK([for $CXX option to enable $1],
     90  [my_CACHE],
     91  [my_CACHE=no
     92   AS_VAR_PUSHDEF([my_save_CXX], [yat_cxx_$1_save_CXX])dnl
     93   my_save_CXX="$CXX"
    4494# From autoconf 'c.m4' we have
    4595# GCC -std=c++11 -std=c++0x
     
    52102# but first we try with empty string, hoping compiler is modern.
    53103   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"],
     104     CXX="$my_save_CXX $yat_arg"
     105     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([$2], [$3])],
     106                       [my_CACHE="$yat_arg"],
    58107                       [])
    59      AS_IF([test x"$yat_cv_cxx_rvalue" != x"no"], [break])
     108     AS_VAR_IF([my_CACHE], [no], [], [break])
    60109   done
    61    CXX="$yat_cxx_rvalue_save_CXX"
     110   # restore CXX
     111   CXX="$my_save_CXX"
     112
     113   AS_CASE([x"$my_CACHE"],
     114           [x], [my_CACHE="none needed"],
     115           [x"no"], [my_CACHE=unsupported])
     116
     117   AS_VAR_POPDEF([my_save_CXX])
    62118  ])
    63119
    64 AS_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])])
    69 AS_VAR_IF([yat_cv_cxx_rvalue], [no], [$2], [$1])
     120AS_CASE([$my_CACHE],
     121        ["none needed"], [$4],
     122        [unsupported], [$5],
     123        [CXX="$CXX $my_CACHE"
     124         $4])
     125AS_VAR_POPDEF([my_CACHE])
    70126])
    71 
    72 
    73 AC_DEFUN([YAT_CXX_RVALUE_HEADER],
    74 [
    75 @%:@include <utility>
    76 
    77 class MyClass
    78 {
    79 public:
    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 
    89 AC_DEFUN([YAT_CXX_RVALUE_BODY],
    90 [
    91   MyClass mc;
    92   MyClass mc2 = std::move(mc);
    93 ])
Note: See TracChangeset for help on using the changeset viewer.