Jump to content
junjieg

range should be instantiated with or without template in the c++ syntax

Recommended Posts

Per 1.0a release

 

the grammar of range in c++ syntax is implemented without template,

however the examples showed us that sometimes we can use it with template,

sometimes we can use it without template,

are the examples which using with template incorrect or not?

see below for details:

 

range header definition in annex C.36, define it without template

===========================================================

C.36 File pss/range.h
#pragma once
#include <vector>
#include "pss/detail/rangeBase.h"
namespace pss {
class Lower {
public:
};
// Used to specify a range that is bounded
// by the domain minimum
const Lower lower;
class Upper {
public:
};
// Used to specify a range that is bounded
// by the domain maximum
const Upper upper;
/// Declare domain of a numeric scalar attribute
class range : public detail::RangeBase {
public:
/// Declare a range of values
range (const detail::AlgebExpr& lhs, const detail::AlgebExpr& rhs);
range (const Lower& lhs, const detail::AlgebExpr& rhs);
range (const detail::AlgebExpr& lhs, const Upper& rhs);
/// Declare a single value
range (const detail::AlgebExpr& value);
/// Copy constructor
range ( const range& a_range);
/// Function chaining to declare another range of values
range& operator() (const detail::AlgebExpr& lhs, const detail::AlgebExpr&
rhs);
/// Function chaining to declare another single value
range& operator() (const detail::AlgebExpr& value);
}; // class range
}; // namespace pss

===========================================================

 

examples without template 8.1.3 Examples

===========================================================

8.1.3 Examples
The DSL and C++ scalar data examples are shown in-line within this section.
DSL: bit [5] in [0..31] b;
C++: attr b { "b", width(5), range (0,31) };
Declare an unsigned variable that is 5-bits wide and has the valid values 1, 2, and 4.
DSL: bit [5] in [1,2,4] c;
C++: attr<bit> c { "c", width(5), range (1)(2)(4) };
Declare an unsigned variable that is 5-bits wide and has the valid values 0..10.
DSL: bit [5] in[..10] b; // 0 <= b <= 10
C++: attr<bit> b {"b", width(5), range(lower,10)};
Declare an unsigned variable that is 5-bits wide and has the valid values 10..31.
DSL: bit [5] in [10..] b; // 10 <= b <= 31
C++: attr<bit> b {"b", width(5), range(10, upper)};

===========================================================

 

examples with template 8.3.3 Examples

===========================================================

DSL: config_modes_e in [MODE_A..MODE_C] mode_ac;
C++: rand_attr<config_modes_e>
mode_ac{"mode_ac",range<config_modes_e>(MODE_A,MODE_C)};
Declare an enum of type config_modes_e with values MODE_A or MODE_C.
DSL: config_modes_e in [MODE_A, MODE_C] mode_ac;
C++: rand_attr<config_modes_e>
mode_ac{"mode_ac",range<config_modes_e>(MODE_A)(MODE_C)};
Declare an enum of type config_modes_e with values UNKNOWN, MODE_A, or MODE_B.
DSL: config_modes_e in [..MODE_B] mode_ub;
C++: rand_attr<config_modes_e>
mode_ub{"mode_ub",range<config_modes_e>(lower,MODE_B)};
Declare an enum of type config_modes_e with values MODE_B, MODE_C, or MODE_D.
DSL: config_modes_e in [MODE_B..] mode_bd;
C++: rand_attr<config_modes_e>
mode_bd{"mode_bd",range<config_modes_e>(MODE_B, upper)};

===========================================================

 

examples with template 8.4.3 Examples

===========================================================

DSL: rand string in ["Hello", "Hallo", "Ni Hao"] hello_s;
C++: rand_attr<std::string>
hello_s{"hello_s",range<std::string>("Hello")("Hallo")("Ni Hao")};

===========================================================

Share this post


Link to post
Share on other sites

Your question is inappropriate for this forum and organization. C++ is used by several of the standards here; however, the definition of C++ and its appropriate use should be redirected to the C++ standards organization elsewhere. This is also not a forum to debate the merits of syntax decisions made elsewhere unless you are proposing and contrasting the syntax with a fundamental language defined here.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...